小编use*_*741的帖子

程序不会去"if"语句

在我的程序中,我允许用户获取随机生成的属性,或输入自己的属性.

当用户输入大于20或小于0的数字时,它应该告诉用户他们输入的数字太大或太小,但它没有.

这是我的代码,主要关注我所说的部分.

if random_var2 == "yes": #if yes
    c2strength = random.randrange(1,20) #randomly generated
    c2skill = random.randrange(1,20)

    print(character2 + ", your strength is: ", c2strength, " and your skill is: ", c2skill) #print out attributes
elif random_var2 == "no": #else
    c2strength = int(input("Enter Strength attribute. Between 1 and 20: ")) #user inputs attributes between 1 and 20
    c2skill = int(input("Enter Skill attribute. Between 1 and 20: "))

    if c2strength < 1 and c2strength > 20: #checks to see …
Run Code Online (Sandbox Code Playgroud)

python if-statement

0
推荐指数
1
解决办法
58
查看次数

标签 统计

if-statement ×1

python ×1