A cookie recipe calls for the following ingredients: • 1.5 cups of sugar • 1 cup of butter • 2.75 cups of flour The recipe produces 48 cookies with this amount of ingredients. Write a program that asks the user how many cookies they want to make and then displays the number of cups of each ingredient needed for the specified number of cookies in the following format: You need 5 cups of sugar, 3 cups of butter, and 7 cups of flour.

Respuesta :

The program that asks the user how many cookies they want to make and then displays the number of cups of each ingredient is corresponds to the ingredients mentioned above.

Further explanation

Python is a general-purpose programming language. We want to write a python program that asks the user how many cookies they want to make and then displays the number of cups of each ingredient.

48 cookies = 1.5 cups of sugar + 1 cup of butter + 2.75 cups of flour, so:

def main():

   cookies = float(input("How many cookies would you like to make?\n>"))

   sugar = (1.5 * cookies) / 48.0

   butter = cookies / 48

   flour = (2.75 * cookies) / 48

   print("To make ", cookies, " cookies, you will need:\n", \

         format(sugar, '.2f'), " cups of sugar\n", \

         format(butter, '.2f'), " cups of butter\n", \

         format(flour, '.2f'), " cups of flour", sep='')

   redoQuery()  

def redoQuery():

   yn = input("Would you like to check another batch size? (y/n)\n>")

   if yn == 'y':

       main()

   elif yn =='n':

       exit()

   else:

       print("Please enter only a lowercase \'y\' or lowercase \'n\'," \

             "then press enter")

       redoQuery()

main()

The run program is shown in the attachment below.

Learn more

1. Learn more about python https://brainly.in/question/8049240

 

Answer details

Grade:  9

Subject: Computers and Technology

Chapter:  programming with python

Keywords: python

Ver imagen tifanihayyu

The program is a sequential program, and does not require loops, iterations and conditions.

The program in Python, where comments are used to explain each line is as follows:

#This gets the number of cookies

cookies = float(input("Number of cookies: "))

#This calculates the amount of sugar

sugar = (1.5 * cookies) / 48.0

#This calculates the amount of butter

butter = cookies / 48

#This calculates the amount of flour

flour = (2.75 * cookies) / 48

#This prints the amount of sugar, butter and flour needed

print("You need ", format(sugar, '.2f'), " cups of sugar, ", format(butter, '.2f'), " cups of butter and ", format(flour, '.2f'), " cups of flour", sep='')

Read more about similar programs at:

https://brainly.com/question/13182195

Otras preguntas