有没有办法我可以做一个石头-布-剪刀游戏,有大于和小于的符号?在
我知道做RPS有不同的方法,但我想具体了解一下“大于”和“小于”。在
这是我的代码:
"Rock" > "Scissors" and 'Rock' < 'Paper'
"Paper" > "Rock" and 'Scissors' < 'Rock'
"Sissors" > "Paper" and 'Paper' < 'Scissors'
choose1 = input("Player One, Enter your answer ")
choose2 = input("Player Two, Enter your answer ")
if choose1 == "Paper":
"Paper" > "Rock"
if choose1 == "Scissor":
"Scissor" > "Rock"
if choose1 != "Rock" and choose1 != "Paper" and choose1 != "Scissors":
print("Player one please chose Rock, Paper, or Scissors")
if choose2 != "Rock" and choose2 != "Paper" and choose2 != "Scissors":
print("Player two please chose Rock, Paper, or Scissors")
if choose1 > choose2:
print('Player1 ({}) beats ({})'.format (choose1, choose2))
else:
print('Player2 ({}) beats ({})'.format (choose2, choose1))
这个游戏起作用了,然而,它认为石头打败了一切,纸打败了剪刀,剪刀却什么也没打。在
如何修复此代码以使其正确执行?在
创建一个选项字典,每个k/v对代表选项,以及该选项将在RPS游戏中“击败”的项目,然后您可以测试两个玩家的选择,如下所示:
一个纯粹的“数学”形式使用的运算符lt和gt,而不需要黑客攻击的运算符可以实现。在
如果您真的想使用
<
和>
,make classes,simple string将不符合您的需要。在编辑:或者最好只使用一个类
^{pr2}$相关问题 更多 >
编程相关推荐