python - 如何修复崩溃程序循环
问题描述
该程序将计算您的更改并报告总金额并循环运行。这是问题启动程序的地方,询问用户他们的名字,如果用户没有输入名字,程序应该退出。插入名称时它开始崩溃。
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')
解决方案
theName == theName
总是正确的,因此你永远不会退出循环
推荐阅读
- ios - 在不同的环境中停止推送通知
- fuzzy-search - 使用模糊逻辑从非结构化数据中检测模式
- go - 相同依赖项的两个版本 - 较低版本被忽略
- facebook-graph-api - 我们如何使用图形 API 获得 Instagram 的故事洞察?
- elasticsearch - Elasticsearch 查询大于日期
- java - 代理在生产中返回“HTTP/1.1 407 需要代理授权”,但在本地工作
- java - 如何从 activemq 中删除已使用的消息?
- javascript - 在 mousedown 上将图像添加到 div 并从数组 jQuery 中删除 mouseup 上的图像
- c# - 通过表单更改实体参数的正确方法
- node.js - 解析错误:意外的令牌,预期的“;” 即使已经有分号