Question

def main(): n = int(input('Enter number of cookies: ')) r = n / 48 sugar =...

def main():
    n = int(input('Enter number of cookies: '))
    r = n / 48
    sugar = r * 1.5
    butter = r
    flour = r * 2.75
    print('You need ' + str(sugar) + ' cups of sugar, ' + str(butter) + ' cups of butter, and ' +
          str(flour) + ' cups of flour for ' + str(n) + ' cookies.')


main() 

Please explain what each function in this program does? Python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def main():
   #reading the number from user
n = int(input('Enter number of cookies: '))
   #dividing it 48
r = n / 48
   #finding number of sugar cups required
sugar = r * 1.5
   #finding number of butter cup required
butter = r
   #finding number of flour cup required  
flour = r * 2.75
   // displaying the all the required details for the given cookies
print('You need ' + str(sugar) + ' cups of sugar, ' + str(butter) + ' cups of butter, and ' +
str(flour) + ' cups of flour for ' + str(n) + ' cookies.')

Add a comment
Know the answer?
Add Answer to:
def main(): n = int(input('Enter number of cookies: ')) r = n / 48 sugar =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A cookie recipe calls for the following ingredients: • 1.5 cups of sugar • 1 cup...

    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...

  • Programming Challenges 145 6. Ingredient Adjuster A cookie recipe calls for the following ingredients: • 1.5...

    Programming Challenges 145 6. Ingredient Adjuster 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 the ingredients. Write a program that asks the user how many cookies he or she wants to make, then displays the number of cups of each ingredient needed for the specified number of cookies. 7. Box Office A movie theater only keeps...

  • THIS CODE IS IN PYTHON #This program calls a function from the main function def getInput():...

    THIS CODE IS IN PYTHON #This program calls a function from the main function def getInput(): ''' This function gets the rate and the hours to calculate the pay ''' userIn = float(input("Enter the rate: ")) print(userIn) inputHours = float(input("Enter the hours: ")) print(inputHours) def main(): getInput() main() YOU NEED TWO FUNCTIONS : main() function get_inputs function

  • THIS IS THE CODE I AM TRYING TO RUN code # def main():       #Reading a as...

    THIS IS THE CODE I AM TRYING TO RUN code # def main():       #Reading a as an integer       a = int(input("Enter value for a: "))       #reading b as an interger       b = int(input("Enter value for b: "))       #reading n as an integer       n = int(input("Enter value for n: "))       # displaying if a and b are congruent modulo n, this is True if a and b       #both returns same remainder when divided by n       if a % n == b...

  • In python using a def main() function, Write a function that will print a hello message,...

    In python using a def main() function, Write a function that will print a hello message, then ask a user to enter a number of inches (should be an integer), and then convert the value from inches to feet. This program should not accept a negative number of inches as an input. The result should be rounded to 2 decimal places(using the round function) and printed out on the screen in a format similar to the example run. Use a...

  • Need help writing this code in python. This what I have so far. def display_menu(): print("======================================================================")...

    Need help writing this code in python. This what I have so far. def display_menu(): print("======================================================================") print(" Baseball Team Manager") print("MENU OPTIONS") print("1 - Calculate batting average") print("2 - Exit program") print("=====================================================================")    def convert_bat(): option = int(input("Menu option: ")) while option!=2: if option ==1: print("Calculate batting average...") num_at_bats = int(input("Enter official number of at bats: ")) num_hits = int(input("Enter number of hits: ")) average = num_hits/num_at_bats print("batting average: ", average) elif option !=1 and option !=2: print("Not a valid...

  • Write a python program write a function numDigits(num) which counts the digits in int num. Answer...

    Write a python program write a function numDigits(num) which counts the digits in int num. Answer code is given in the Answer tab (and starting code), which converts num to a str, then uses the len() function to count and return the number of digits. Note that this does NOT work correctly for num < 0. (Try it and see.) Fix this in two different ways, by creating new functions numDigits2(num) and numDigits3(num) that each return the correct number of...

  • For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the...

    For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. By debugging these programs, you can gain expertise in program logic in general and the Python programming language in particular. def main(): # Local variable number = 0 # Get number as input from the user. number = int(input('How many numbers to display? ')) # Display the numbers. print_num(number) # The print_num function is a a recursive function #...

  • in python and according to this #Creating class for stack class My_Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def Push(self, d): self.items.append(d) def Po...

    in python and according to this #Creating class for stack class My_Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def Push(self, d): self.items.append(d) def Pop(self): return self.items.pop() def Display(self): for i in reversed(self.items): print(i,end="") print() s = My_Stack() #taking input from user str = input('Enter your string for palindrome checking: ') n= len(str) #Pushing half of the string into stack for i in range(int(n/2)): s.Push(str[i]) print("S",end="") s.Display() s.Display() #for the next half checking the upcoming string...

  • Can you please enter this python program code into an IPO Chart? import random def menu():...

    Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT