这是Python 3.如果用户在池中剩余0个点,并且已从键值中取得点并将其添加回池中,则程序将中断。这让我感到困惑,因为在这一点上,pool> 0,第一个while循环应该启动,但不是。任何人都可以提供任何解释为什么?代码意外中断
PS-general code critique also appreciate。这是新的。
pool = 30
attr = {'Strength' : 0, 'Health' : 0, 'Wisdom' : 0, 'Dexterity' : 0}
while pool > 0:
print('\t\t Time to spend some points! You have', pool, 'to spend')
spend = input('Where would you like to spend your points?')
if spend in attr:
amount = int(input('How many points would you like to spend?'))
if amount > pool:
print('You do not have that many points! You have', pool, 'points!')
else:
attr[spend] = amount
pool -= amount
print(attr)
else:
print('Not a valid input. Please correct.')
print('\t\t You have no more points! Add some to the pool!')
while pool == 0:
confirm = input('Would you like to add points back into the pool?')
if confirm == 'y':
take = input('Where would you like to take points from?')
if take in attr:
number = int(input('How many points would you like to take?'))
if attr[take] >= number:
pool += number
attr[take] -= number
print ('There are now', pool, 'points remaining')
elif attr[take] < number:
print('You dont have enough points to do that! You have', attr[take], 'points in', take)
else:
print('Please make a valid selection.')
elif confirm == 'n':
print('Goodbye!')
break
最有可能的,因为'pool'不是'> 0',但既然你不显示的代码的一部分,没有人会知道。 –
Ach!修复。抱歉。那里。但是当用户在第二个while循环内添加更多点时,它是> 0。 – Zack