我的评论说明了我的推理思路,但很明显我错了。我的代码直接跳到“你的债务总额是…”
# Dictionary of Bills
expenses = {'mortgage':[], 'personal':[], 'power':[], 'insurance':[], 'water':[], 'food':[], 'savings':[], 'fuel':[], 'phone':[], 'internet':[], 'credit':[], 'emergencies':[]}
totalDebt = 0
switch = "A"
while switch == switch.isalpha(): # Condition is true, switch is a letter
for each in expenses: # Iterates through each bill
debt = input("%s: "%each) # User input
if debt.isdigit(): # checks to make sure they only enter numbers
debt = int(debt) # Converts debt to its integer value
totalDebt = totalDebt + debt # adds debt to keep a running total.
else: # User entered something other than a number
print("Only enter digits!")
print("Your total Debt is: $%i" %totalDebt)
input("Press Enter to continue: ")
print("What is this fortnights Income?")
这是假的
你必须使用交换机.isalpha()全部
你的情况在这里毫无意义:
switch.isalpha()
返回True
或False
。switch
本身将不等于这两个值中的任何一个,因此整个表达式总是False
。删除相等测试:请注意,您的代码实际上从未更改
switch
,因此现在您的循环将永远继续。你知道吗相关问题 更多 >
编程相关推荐