這是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