虽然循环在Python

时间:2016-01-22 21:11:35

标签: python loops while-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

2 个答案:

答案 0 :(得分:3)

要进行打印,您必须排除=(因为它会为变量赋值)

 printInfo = (totalBottles, totalPayout)

必须是:

 printInfo(totalBottles, totalPayout)

这样就可以用变量调用函数。

答案 1 :(得分:0)

您正在为一个函数分配tuple(totalBottles,totalPayout),这就是为什么不起作用的原因。

printInfo是一个函数,仅打印并且没有返回...因此更改语句

printInfo = (totalBottles, totalPayout)

代表printInfo(totalBottles, totalPayout)