[英]While loop is not working in Python
The program will allow me to input the values, but their is no calculations and it doesn't print. 该程序将允许我输入值,但它们不是计算值,也不会打印。 I have moved the endProgram input all over and it just turns it into an infinite loop.
我已经将endProgram输入全部移开,它只是将其变成无限循环。
def main ():
endProgram = "no"
while endProgram == "no":
totalBottles = getBottles()
totalPayout = calcPayout(totalBottles)
printInfo = (totalBottles, totalPayout)
endProgram = raw_input("Do you want to end the program? Enter yes or no:")
def getBottles():
counter = 1
totalBottles = 0
todayBottles = 0
while counter <= 7:
todayBottles = input("Enter number of bottles for today:")
totalBottles = totalBottles + todayBottles
counter = counter + 1
return totalBottles
def calcPayout(totalBottles):
totalPayout = 0
totalPayout = totalBottles * .10
return totalPayout
def printInfo(totalBottles,totalPayout):
print "The total bottles collected is:",totalBottles
print "The total payout is $ :",totalPayout
To print you have to remove =
in line (because it assigns values to variable) 要打印,您必须在行中删除
=
(因为它将值分配给变量)
printInfo = (totalBottles, totalPayout)
It has to be: 它一定要是:
printInfo(totalBottles, totalPayout)
This way you call function with variables. 这样,您可以通过变量调用函数。
You are assigning a tuple (totalBottles, totalPayout) to a function, that is the reason why is not working. 您正在将一个元组 (totalBottles,totalPayout)分配给一个函数,这就是为什么不起作用的原因。
printInfo
is a function that only prints and has no returns... therefore change the statement printInfo
是一个仅打印而没有返回值的函数,因此请更改语句
printInfo = (totalBottles, totalPayout)
for printInfo(totalBottles, totalPayout)
用于
printInfo(totalBottles, totalPayout)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.