【发布时间】:2020-05-21 05:54:11
【问题描述】:
下面的代码是我的课程中使用的。目前,“if int(what_skill) 9:”行正在产生上述错误。我尝试将其更改为 str() 但这会产生另一个错误。
定义播放器():
vigor = 1
endurance = 1
strength = 1
dexterity = 1
intelligence = 1
luck = 1
points = 25
while points !=0:
what_skill = input("What skill would you like to add to? Vigor, Endurance, Strength, Dexterity, Intelligance, Luck? ")
print(what_skill)
add_points = int(input("You have " + str(points) + " points left. How many points from 1-9 would you like to add to " + str(what_skill) + "? "))
if int(add_points) > 9:
print("Too many points")
print(add_points)
else:
if int(what_skill) < 0 or int(what_skill) > 9:
print("invaid choice")
else:
update_skill = int(what_skill) + int(add_points)
points = points - add_points
【问题讨论】:
-
"Luck" 是一个字符串——你试图将它转换为一个 int 是没有意义的
-
what_skill是技能name,你的积分是add_points,所以int(what_skill)显然会破码。
标签: python python-3.x loops variables exception