在我的Python游戏中,我做了一个掷骰子的游戏,如果你猜对了数字,我就开始工作了,但是我正在尝试开发一个更高或更低的部分
但在我的代码中,如果值是3,你说得更高,它会说你赢了。你知道吗
示例#debug (5)
Would you like to bet on higher or lower <h:l> <: l
You won congrats!
但我应该在这里输而不是赢。你知道吗
elif user_nh == 'high':
print(system_number)
hiLo = str(input("Would you like to bet on higher or lower <h:l> <: "))
if hiLo == 'l' and system_number == 1 or system_number == 2 or system_number == 3:
print("You won congrats")
pa = str(input("Would you like to play again y/n :> "))
if pa == 'n':
break
if pa == 'y':
continue
else:
print("You supplied a invalid response, quitting game.")
break
if hiLo == 'h' and system_number == 4 or system_number == 5 or system_number == 6:
print('You won congrats!')
pa = str(input("Would you like to play again y/n :> "))
if pa == 'n':
break
if pa == 'y':
continue
else:
print("You supplied a invalid response, quitting game.")
break
这条线:
是这样评估的:
所以
hiLo == 'l'
部分(当前)只影响第一个system_number == 1
测试。如果system_number
是2或3,则无论hiLo
的值是多少,代码都将进入块。你知道吗这是因为
or
运算符比and
运算符有一个higher precedence。你知道吗所以你可能想要这样的东西:
或者
或者
更好的是,既然您已经定义了较高和较低的数字,您不妨使用它们,如下所示:
第39行:
第49行:
用括号括起来:
但是你最好这样做:
相关问题 更多 >
编程相关推荐