如何解决错误:int()以10为底的无效文字:“运气”?

查尔斯·斯帕克斯

下面的代码是我的课程中使用的代码。目前,“如果int(what_skill)<0或int(what_skill)> 9:”行将产生上述错误。我尝试将其更改为str(),但这会产生另一个错误。

def player():

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
AK 47

您看到错误的原因是由于线条

int(what_skill)

在您的示例中,这等于

int("luck")

这没有任何意义-我想您正在尝试int(luck)-引用变量中的数字

我会将您的技能更改为词典,并使用以下内容:

stats = {
  "Luck": 1,
  "Vigor": 1,
  "Endurance": 1,
  "Strength": 1,
  "Dexterity": 1,
  "Intelligence" : 1
}

points = 25
while points >= 1:
    what_skill = input("What skill would you like to add to? Vigor, Endurance, Strength, Dexterity, Intelligance, Luck? ")
    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")
    else:
        if stats[what_skill] < 0 or stats[what_skill] > 9:
            print("invalid choice")
        else:
            update_skill = stats[what_skill] + int(add_points)
            points = points - add_points

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何解决:值错误,以int()为基数10:“ Shuk”的无效文字?

错误:ValueError:int()以10为底的无效文字

Python 3错误:ValueError:以10为底的int()的无效文字:''

我的模型错误:以10为底的int()无效文字:

如何在熊猫中以10为底的错误修复int()的无效文字

如何修复以10为底的int()的ValueError:无效文字?

例外:int()以10为底的无效文字:''

ValueError以10为底的int()的无效文字:''

ValueError:int()以10为底的无效文字

ValueError:int()以10为底的无效文字:''

以10为底的int()的无效文字:'n'

为以10为底的int()建模Django无效文字:“无”

当标识的值是一个字符串时,如何解决“以 10 为基数的 int() 的无效文字”错误

使用python tkinter会出现错误:以10为底的int()的无效文字:''

我不能将两个字段相乘。错误:int()以10为底的无效文字:

如何在Django中解决错误“ int()的无效文字,基数为10:'独立'?

以10为底的int()无效文字:“ educationlevel_api”

ValueError:int()以10为底的无效文字:“ 0.5”

以10为底的int()无效文字:“ 2,674”

ValueError:以10为底的int()的无效文字:''(Tkinter)

以10为底的int()无效文字:“需要审核”

对于以10为底的int(),Django manytomany字段无效的文字:''

Python:ValueError:以10为底的int()的无效文字:''

sqlalchemy对于以10为底的int()无效文字

以10为底的int()的无效文字:“ pk” Python / Django

Django:ValueError:以10为底的int()的无效文字:

django ValueError:以10为底的int()的无效文字:

{ValueError:以10为底的int()的无效文字:}在处理整数时

django int()的无效文字,以10为底:'game_count'