Python 使用while循环时,如何计算运行总数?
我很难理解这段代码(我是新来的,所以请温柔一点),试图编写一个跟踪卡路里的程序,但我无法获得代码:Python 使用while循环时,如何计算运行总数?,python,python-3.x,Python,Python 3.x,我很难理解这段代码(我是新来的,所以请温柔一点),试图编写一个跟踪卡路里的程序,但我无法获得代码: caloriesPerMeal = int(input('Enter calories eaten per meal: ')) 当它回顾并再次询问我是否要进入另一顿饭时添加到自身中(如下所示): 我的全部代码是: keepGoing = 'yes' totalCalories = 0 #Calories per Day maxCaloriesPerDay = int(input('How man
caloriesPerMeal = int(input('Enter calories eaten per meal: '))
当它回顾并再次询问我是否要进入另一顿饭时添加到自身中(如下所示):
我的全部代码是:
keepGoing = 'yes'
totalCalories = 0
#Calories per Day
maxCaloriesPerDay = int(input('How many calories per day would you like to consume? '))
while keepGoing == 'yes':
#Get number of calories per meal
caloriesPerMeal = int(input('Enter calories eaten per meal: '))
totalCalories += totalCalories + caloriesPerMeal
#See if user wants to input another meal
keepGoing = input('Do you want to enter another meal? (Enter yes or no) ')
#Calculate calories under/over per day
if totalCalories >= maxCaloriesPerDay:
print('You are', maxCaloriesPerDay - totalCalories, 'calories over your maximum calories per
day.')
elif totalCalories <= maxCaloriesPerDay:
print('You are', maxCaloriesPerDay - totalCalories, 'calories under your maximum calories per
day. ')
keepGoing='yes'
总热量=0
#每天卡路里
maxCaloriesPerDay=int(输入('您希望每天消耗多少卡路里?'))
而keepGoing==“是”:
#每餐摄入多少卡路里
CarloresPermeal=int(输入('输入每餐摄入的卡路里:'))
总卡路里+=总卡路里+卡路里值
#查看用户是否要输入另一顿饭
keepGoing=input('您想输入另一顿饭吗?(输入是或否)')
#计算每天低于/超过的卡路里
如果TotalCarries>=MaxCarriesPerday:
打印('您是',MaxCarriesPerday-TotalCarries,'卡路里超过您每天的最大卡路里')
一天
elif TotalCarries试着做:
totalcarries=totalcarries+carriespermeal
keepGoing = 'yes'
totalCalories = 0
#Calories per Day
maxCaloriesPerDay = int(input('How many calories per day would you like to consume? '))
while keepGoing == 'yes':
#Get number of calories per meal
caloriesPerMeal = int(input('Enter calories eaten per meal: '))
totalCalories += caloriesPerMeal
#See if user wants to input another meal
keepGoing = input('Do you want to enter another meal? (Enter yes or no) ')
#Calculate calories under/over per day
if totalCalories >= maxCaloriesPerDay:
print('You are', maxCaloriesPerDay - totalCalories, 'calories over your maximum calories per day.')
elif totalCalories <= maxCaloriesPerDay:
print('You are', maxCaloriesPerDay - totalCalories, 'calories under your maximum calories per day. ')
或:
totalcarries+=carriespermal
keepGoing = 'yes'
totalCalories = 0
#Calories per Day
maxCaloriesPerDay = int(input('How many calories per day would you like to consume? '))
while keepGoing == 'yes':
#Get number of calories per meal
caloriesPerMeal = int(input('Enter calories eaten per meal: '))
totalCalories += caloriesPerMeal
#See if user wants to input another meal
keepGoing = input('Do you want to enter another meal? (Enter yes or no) ')
#Calculate calories under/over per day
if totalCalories >= maxCaloriesPerDay:
print('You are', maxCaloriesPerDay - totalCalories, 'calories over your maximum calories per day.')
elif totalCalories <= maxCaloriesPerDay:
print('You are', maxCaloriesPerDay - totalCalories, 'calories under your maximum calories per day. ')
因为说总热量+=总热量+卡路里能量值意味着
totalcarries=2*totalcarries+carriespermeal
试着做:
keepGoing = 'yes'
totalCalories = 0
#Calories per Day
maxCaloriesPerDay = int(input('How many calories per day would you like to consume? '))
while keepGoing == 'yes':
#Get number of calories per meal
caloriesPerMeal = int(input('Enter calories eaten per meal: '))
totalCalories += caloriesPerMeal
#See if user wants to input another meal
keepGoing = input('Do you want to enter another meal? (Enter yes or no) ')
#Calculate calories under/over per day
if totalCalories >= maxCaloriesPerDay:
print('You are', maxCaloriesPerDay - totalCalories, 'calories over your maximum calories per day.')
elif totalCalories <= maxCaloriesPerDay:
print('You are', maxCaloriesPerDay - totalCalories, 'calories under your maximum calories per day. ')
totalcarries=totalcarries+carriespermeal
keepGoing = 'yes'
totalCalories = 0
#Calories per Day
maxCaloriesPerDay = int(input('How many calories per day would you like to consume? '))
while keepGoing == 'yes':
#Get number of calories per meal
caloriesPerMeal = int(input('Enter calories eaten per meal: '))
totalCalories += caloriesPerMeal
#See if user wants to input another meal
keepGoing = input('Do you want to enter another meal? (Enter yes or no) ')
#Calculate calories under/over per day
if totalCalories >= maxCaloriesPerDay:
print('You are', maxCaloriesPerDay - totalCalories, 'calories over your maximum calories per day.')
elif totalCalories <= maxCaloriesPerDay:
print('You are', maxCaloriesPerDay - totalCalories, 'calories under your maximum calories per day. ')
或:
totalcarries+=carriespermal
keepGoing = 'yes'
totalCalories = 0
#Calories per Day
maxCaloriesPerDay = int(input('How many calories per day would you like to consume? '))
while keepGoing == 'yes':
#Get number of calories per meal
caloriesPerMeal = int(input('Enter calories eaten per meal: '))
totalCalories += caloriesPerMeal
#See if user wants to input another meal
keepGoing = input('Do you want to enter another meal? (Enter yes or no) ')
#Calculate calories under/over per day
if totalCalories >= maxCaloriesPerDay:
print('You are', maxCaloriesPerDay - totalCalories, 'calories over your maximum calories per day.')
elif totalCalories <= maxCaloriesPerDay:
print('You are', maxCaloriesPerDay - totalCalories, 'calories under your maximum calories per day. ')
因为说总热量+=总热量+卡路里能量值意味着
totalcarries=2*totalcarries+carriespermeal
keepGoing='yes'
keepGoing = 'yes'
totalCalories = 0
#Calories per Day
maxCaloriesPerDay = int(input('How many calories per day would you like to consume? '))
while keepGoing == 'yes':
#Get number of calories per meal
caloriesPerMeal = int(input('Enter calories eaten per meal: '))
totalCalories += caloriesPerMeal
#See if user wants to input another meal
keepGoing = input('Do you want to enter another meal? (Enter yes or no) ')
#Calculate calories under/over per day
if totalCalories >= maxCaloriesPerDay:
print('You are', maxCaloriesPerDay - totalCalories, 'calories over your maximum calories per day.')
elif totalCalories <= maxCaloriesPerDay:
print('You are', maxCaloriesPerDay - totalCalories, 'calories under your maximum calories per day. ')
总热量=0
#每天卡路里
maxCaloriesPerDay=int(输入('您希望每天消耗多少卡路里?'))
而keepGoing==“是”:
#每餐摄入多少卡路里
CarloresPermeal=int(输入('输入每餐摄入的卡路里:'))
总卡路里+=卡路里当量
#查看用户是否要输入另一顿饭
keepGoing=input('您想输入另一顿饭吗?(输入是或否)')
#计算每天低于/超过的卡路里
如果TotalCarries>=MaxCarriesPerday:
打印('您是',MaxCarriesPerday-TotalCarries,'每天超过最大卡路里的卡路里')
elif totalcarrieskeepGoing='是'
总热量=0
#每天卡路里
maxCaloriesPerDay=int(输入('您希望每天消耗多少卡路里?'))
而keepGoing==“是”:
#每餐摄入多少卡路里
CarloresPermeal=int(输入('输入每餐摄入的卡路里:'))
总卡路里+=卡路里当量
#查看用户是否要输入另一顿饭
keepGoing=input('您想输入另一顿饭吗?(输入是或否)')
#计算每天低于/超过的卡路里
如果TotalCarries>=MaxCarriesPerday:
打印('您是',MaxCarriesPerday-TotalCarries,'每天超过最大卡路里的卡路里')
elif TotalCarries哇,我觉得这是一个傻瓜哈哈,这么简单的解决方案,但非常感谢你!哇,我觉得自己像个傻瓜,哈哈,这么简单的解决方案,但非常感谢你!谢谢你的帮助,如此简单的解决方案我刚刚看过:)谢谢你的帮助,如此简单的解决方案我刚刚看过:)