I am in a Fundamentals of Programming class which we are using Python. In the book was a simple code to solve a problem where a cook knows in cups how much he needs but we are converting it to ounces. I was playing around with that and trying to figure out the if-else, elif commands. It is telling me where it says
if choice ==1:
that there is a syntax error.
Can someone let me know what I am doing wrong?
def main(): intro() c2o = 1 o2c = 2 choice = int(input('Enter 1 if you would like to convert cups to ounces', \ 'or enter 2 if you would like to convert ounces to cups.') if choice == 1: cups_needed = int(input('Enter the number of cups: ')) cups_to_ounces(cups_needed) elif choice == 2: ounces_needed = int(input('Enter the number of ounces: ')) ounces_to_cups(ounces_needed) print() def intro(): print('This program converts measurements') print('in cups to fluid ounces or fluid ounces to cups. For your') print('reference the formula is:') print(' 1 cup = 8 fluid ounces or 8 fluid ounces = 1 cup') print() def cups_to_ounces(cups): ounces = cups * 8 print('That converts to', ounces, 'ounces.') def ounces_to_cups(ounces): cups = ounces / 8 print('That converts to', cups, ' cups.') main()
Edited 4 Years Ago by nUmbdA