Lab 0

Repl link. Complete this program. If the program is completed in the repl project, replace the code with this:

# Computations with Candy Bars
print("This program will allow you to make calculations about your bag of candy bars.")
nameCandyBar = input("What kind of candy bars do you have? ")
print("Answer the following questions about your",nameCandyBar,"bars.")
numCandyBar = int(input("Enter the number of candy bars in a package: "))
weightCandyBar = float(input("Enter the weight in ounces of one candy bar: "))
totalWeight = weightCandyBar * numCandyBar

print(numCandyBar,nameCandyBar,"bars")
print(weightCandyBar," ounces each")
print("Total weight is ",totalWeight,"ounces.")

print("Perhaps you should consider a healthier snack!")

# Now add a new variable caloriesPerBar. 
# What should be the type?
# Add an input prompt asking the user to 
# enter the number of calories per
# bar. 

# Add a statement to compute and output the 
# total number of calories given the number 
# of candy bars.



#  Assume that the typical bite of a candy bar 
# is 0.7 ounces. Add code to display the number 
# of bites per bar, and the total number of bites 
# for all the bars. What types did you use for the variables? Why?
# For example if a bar is 2.1oz, then the number of bites is
# 2.1/0.7 which is 3 bites.


# A person burns (weight * .57) calories per 
# mile walking, and (weight * .72) calories 
# per mile running. Ask the person for 
# their weight, and tell them how many miles 
# they would need to run or walk to burn off 
# one candy bar, and how many for the whole
# package.


# Write out  message, as a sentence, explaining
# how much exercise must be done to use up 
# the calories of the candy bars, then encourage 
# the user to eat something healthier.  
# Include the name of the candy bars in 
# the output.

Scroll to Top