Search code examples
pythonstringrecipe

Python coding trouble


For homework, I am supposed to code a recipe that takes the input of the deserts and spit out how much of the ingredients would be required. I'm still new and keep getting this error code, but could possibly be wrong altogether?

print("Welcome to Carmack's Bakery")

 cookies = int(input('How many dozen cookies? ==> ') )
print(cookies)

 cakes = int(input('How many cakes? ==> ') )
print(cakes)

donuts = int(input('How many dozen donuts? ==> ') )
print(donuts)



 cake_eggs = 2
 cake_butter = .5
 cake_sugar = 1
 cake_flour = 1.5

   cookie_eggs = 2
 cookie_butter = 2.5
  cookie_sugar = 2
   cookie_flour = 8


 donuts_eggs = 3
  donuts_butter = .25
  donuts_sugar = .5
 donuts_flour = 5

 print('You will need to order')

  cookies_dozen = float('cookie_eggs' + 'cookie_butter' + 'cookie_sugar' + 
   'cookie_flour' * 'cookies')
    print ('cookies_dozen' ('cups of butter'))

this is my error code: come up with code snippets (a line or two of code) that produce 10 different types of errors


Solution

  • cakes = int(input('How many cakes? ==> '))
    donuts = int(input('How many dozens of donuts? ==> '))
    cookies = int(input('How many dozen cookies? ==> '))
    
    cake_eggs = 2
    cake_butter = .5
    cake_sugar = 1
    cake_flour = 1.5
    
    cookie_eggs = 2
    cookie_butter = 2.5
    cookie_sugar = 2
    cookie_flour = 8
    
    donuts_eggs = 3
    donuts_butter = .25
    donuts_sugar = .5
    donuts_flour = 5
    
    total_butter = cake_butter*cakes + cookie_butter*cookies + donuts_butter*donuts
    total_eggs = cake_eggs*cakes + cookie_eggs*cookies + donuts_eggs*donuts
    total_sugar = cake_sugar*cakes + cookie_sugar*cookies + donuts_sugar*donuts
    total_flour = cake_flour*cakes + cookie_flour*cookies + donuts_flour*donuts
    
    print('You need to order : \n' + 'Eggs = ' + str(total_eggs)+'\n' + 'Butter = ' + str(total_butter) +'\n' + 'Sugar : ' + str(total_sugar) + '\n' + 'Flour = ' + str(total_flour) )
    

    Here, to concatenate string with numbers, you have to convert number to string, using str() method.