pointsToAdd = 30
strengthPoints = 0
healthPoints = 0
wisdomPoints= 0
dexterityPoints = 0
while pointsToAdd > 0:
choice = int(input("Choice(1-4): "))
if choice == 1:
pointsToAdd = int(input("How many Strength points would you like to add: "))
if pointsToAdd < 31 and pointsToAdd > 0 and pointsToAdd - strengthPoints > 0:
strengthPoints += pointsToAdd
pointsToAdd -= strengthPoints
print("You now have",strengthPoints,"strength points")
elif pointsToAdd > 30:
print("You cannot add that many!")
elif pointsToAdd<1:
print("You cannot add less than one point!")
elif pointsToAdd - strengthPoints <= 0:
print("You only have",pointsToAdd,"points!")
else:
print("We are sorry, but an error has occurred")
我試圖讓用戶可以爲四個類別中的任何一個輸入點,但花費不超過30個點(我還沒有編寫代碼健康,智慧或敏捷點)。爲什麼當我運行程序時,如果你選擇在1-30之間添加點數,循環只能再次運行?如果用戶使用不在1-30之間的數字輸入他們想要分配給strengthPoints
的點,則循環將運行關聯的if語句,但不會再次通過循環,爲什麼會出現這種情況?儘管Python中的循環無法正常工作
只是一點點修正:::我所知,輸入已經返回INT,無需INT(intput)() – Pythonizer
@Streak不在python3這顯然OP寫正在使用(打印功能而不是語句)。 – Hyperboreus