eko


Joined 1 year ago
Homeworks submitted:
Homework comments:
3
0

About Me

No description provided.

Classes

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming

Class status: Established
Role: Student
. 17% complete

Submitted Assignments

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 3, HW 1
#problem 3 -mcnuggets


count=0

n=1
exact=0

while count<6 :
  
    for a in range (0,9) :
        for b in range (0,6) :
            for c in range (0,3):
                if 6*a + 9*b + 20*c == n :
                    exact=1
    if exact == 1 :
        count +=1
    else :
        largest=n
        count=0
    n+=1
    exact=0          

print "Largest number of McNuggets that cannot be bought in exact quantity: "largest

----------------------------------------------------

#problem 4 -mcnuggets



x=(int(raw_input("small package size: ")))
y=(int(raw_input("medium package size: ")))
z=(int(raw_input("large package size: ")))

up=(int(raw_input("up to what number to check?")))

packages=(x,y,z)
count=0
n=1
bestSoFar=0
exact=0
flag=0


while count<x :
  for n in range (1,up):
    for a in range (0,up/x+x) :
        for b in range (0,up/y+y) :
            for c in range (0,up/z+z):
                if x*a + y*b + z*c == n :
                    exact=1
    if exact == 1 :
        count +=1
    else :
        bestSoFar=n
        count=0
    n+=1
    exact=0          
  if count<x :
      flag=1
      print "There is no number up to ",up ,"which cannot be bought"
      break

if flag!=1:
    print "Given package sizes ",x ,y, z
    print "the largest number of McNuggets that cannot be bought"
    print "in exact quantity is: ",bestSoFar

eko 1 year ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 2, HW 1
#Problem 1

n=int(raw_input("insert which prime you want to know:"))

pres=2
count=1
div=2

while count<=n :  # count prime numbers up to n

    while pres/2>div :  #check if divides to numbers up to half   current
        if pres%div==0 :
            div=pres+1    #not a prime, make divisor to be false on next conditions 
        else:
            div+=1     #check next number as divisor
    if pres>=div:
            count+=1  #prime, count one up
            prime=pres
    if pres==2:    #special case of 2
            pres+=1
    else:
            pres+=2   #3 and up, check through odd numbers only
    div=2  #reset divisor to 2

                                  
print "The ",n,"prime no. is ",prime  #print the n prime

-------------------

#Problem 2

import math

n=int(raw_input("which n to sum up to:"))

pres=2
div=2
sum=0

while pres<=n :  # count prime numbers up to n

    while pres/2>div :  #check if divides to numbers up to half current

        if pres%div==0 :
            div=pres+1    #not a prime, make divisor to be false on next conditions 
        else:
            div+=1     #check next number as divisor
            
    if pres>=div:
        prime=pres         #current number is a prime, find log and add to sum
        pl=math.log(prime)
        sum+=pl
    if pres==2:    #special case of 2
        pres+=1
    else:
        pres+=2   #3 and up, check through odd numbers only
    div=2  #reset divisor to 2

                                  
print "The sum of the logs of the primes is ",sum
print "The number n is ",n
ratio=sum/n
print "The ratio of the two above is ",ratio

eko 1 year ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 1, HW 1
a=raw_input('Enter your last name:')
b=raw_input('Enter your first name:')
print b
print a

eko 1 year ago