use*_*741 0 python if-statement
在我的程序中,我允许用户获取随机生成的属性,或输入自己的属性.
当用户输入大于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 if it's in bounds #HERE
print("Please enter an attribute that is between 1 and 20. ")
var()
else: #if it is
pass
if c2skill < 1 and c2skill > 20:
print("Please enter an attribute that is between 1 and 20. ")
var()
Run Code Online (Sandbox Code Playgroud)
问题是什么?
谢谢