The question I must complete is as follows;
After caffeine is absorbed into the body, 13% is eliminated from the body each hour. Assume an 8-oz cup of brewed coffee contains 130 mg of caffeine and the caffeine is absorbed immediately into the body. Write a program that allows the user to enter the number of cups of coffee consumed. Write an indefinite loop (while) that calculates the caffeine amounts in the body until the number drops to less than 65 mg
This is what I currently have
def main():
cup = float(input("Enter number of cups of coffee:"))
caff = cup * float(130)
while caff <= 65:
caff -= caff * float(0.13)
main()
The output must present a column with the amount of hours that have passed on the left and the remaining amount of caffeine on the right. I am looking for guidance as to where I should go from here. Thanks.
You need another variable counting the number of hours. Then just print the two variables in the loop.
You also need to invert the test in the while
. You want to keep looping while the amount of caffeine is at least 65 mg.
def main():
cup = float(input("Enter number of cups of coffee:"))
caff = cup * float(130)
hours = 0
while caff >= 65:
caff -= caff * float(0.13)
hours += 1
print(hours, caff)
main()