首页 > 解决方案 > 如何修复崩溃程序循环

问题描述

该程序将计算您的更改并报告总金额并循环运行。这是问题启动程序的地方,询问用户他们的名字,如果用户没有输入名字,程序应该退出。插入名称时它开始崩溃。

def calculateChanges( quarters, dimes, nickels, pennies):
    twentyFive = .25
    tens = .10
    fives = .05
    ones = .01
    twentyFive = int(twentyFive) * int(quarters)
    tens = int(tens) * int(dimes)
    fives = int(fives) * int(nickels)
    ones = int(ones) * int(pennies)
    combineAll = twentyFive + tens + fives + ones
    return combineAll

theName = input('What is your name (Return/Enter to quit)?')

while theName == theName:
    theFirst = input('How many quarter do you have? ')
    theSecond = input('How many dimes do you have? ')
    theThird = input('How many nickels do you have? ')
    theLast = input('How many pennies do you have? ')

    justTotal = calculateChanges(theFirst, theSecond, theThird, theLast)
    print('All counted,',theName, 'has: $'+ str(justTotal))

    else:
        print('Bye')

标签: pythonloops

解决方案


theName == theName总是正确的,因此你永远不会退出循环


推荐阅读