Question: Paste the following code into a new Python file. Find the errors. # main module def main(): try: # Get grams fat. gramsFat = float(input('Enter
Paste the following code into a new Python file. Find the errors.
# main module
def main():
try:
# Get grams fat.
gramsFat = float(input('Enter the fat grams consumed: '))
# Get grams carbs.
gramsCarbs = float(input('Enter the carbohydrate grams consumed: '))
# Calculate calories from fat.
caloriesFat = gramsFat * CALORIES_FROM_FAT
# Calculate calories from carbs.
caloriesCarbs = gramsCarbs + CALORIES_FROM_CARBS
# Print calories.
showCarbs(gramsFat, gramsCarbs, caloriesFat, caloriesCarbs)
except TypeError:
print(' Please enter valid numbers.')
# The showCarbs function accepts the number of grams of fat and
# of carbs, as well as the calories from fat and from carbs, as
# arguments and displays the resulting calories.
def showCarbs(gramsCarbs, gramsFat, caloriesFat, caloriesCarbs):
print(' Grams of fat: ', format(gramsFat, '.2f'))
print('Fat calories: ', format(caloriesFat, '.2f'))
print('Grams of carbs: ', format(gramsCarbs, '.2f'))
print('Carb calories: ', format(caloriesCarbs, '.2f'))
# Call the main function.
main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
