weight - Pounds and Ounces in Python -
i started learn coding , i'm having issue trying pounds converted on ounces. we're suppose allow user input data 6 pounds 2 ounces. i'm stuck @ moment , i'm not sure if i'm going right. appreciated.
your program accept input weights in pounds , ounces set of rabbits fed 1 type of food. let user provide name of food. accept input until user types 0 weight. make life easier converting weights ounces. compute arithmetic mean (average) of each set of rabbits. determine set of rabbits weighs most, reporting average weight.
this orignal code before using pounds , ounces , worked fine using simple number 13.
f1 = input("name of food:") print (f1) counter = 0 sum = 0 question = input('''enter weight? type "yes" or "no" \n\n''') while question == "yes" : ent_num = int(input("weight of rabbit:")) sum = sum + ent_num counter = counter + 1 question = input('''enter weight? type "yes" or "no". \n ''') print ("average weight " + str(sum/counter))
my current code looks after tried implement pounds , ounces input.
f1 = input("name of food: ") print (f1) counter = 0 sum = 0 print ("please enter inforamtion in pounds , ounces. end") question = input('''enter weight? type "yes" or "no" \n\n''') while question == "yes" : ent_num = int(input("weight of rabbit:")) sum = sum + ent_num counter = counter + 1 if pounds * ounces == 0: allounces = pounds * 16 + ounces sum = sum + allounces print ("average weight " + str(sum/counter))
you need save pounds , ounces in separate variable needed.
f1 = input("name of food: ") print (f1) counter = 0 sum = 0 print ("please enter inforamtion in pounds , ounces. end") question = input('''enter weight? type "yes" or "no" \n\n''') while question == "yes" : pounds, ounces = map(int, input().split()) weight = pounds * 16 + ounces sum = sum + weight counter = counter + 1 if pounds * ounces == 0: print ("average weight " + str(sum/counter))
Comments
Post a Comment