我对Python不熟悉,但写了简单的石头、布和剪刀游戏。 在
代码如下。 from _ _ future _ _ import print _ function
导入随机
name=raw_input('hi,I'm PyVa. What is your name: ) ) ) ) ) )。
print('hi ',name,end='.' )
ESO rno=raw _ input (wouldyouliketoplayrock,Paper,Scissors? ' )
ysorno=str (是rno ) ) )。
if yeso rno==str (是) ) :
choices=['Rock '、' Paper '、' Scissors']
打印(确定) )。
your _ choice=raw _ input (选择锁定,Paper or Scissors: ) )
打印(' my turn . ' ) )。
my _ choice=random.choice (choices )
打印(I choose,),my_choice ) )。
if your_choice==my_choice:
打印(webothchoosethesame,it is a draw.' )。
elif your _ choice==' rock ' and my _ choice==' paper ' :
打印(iwin! ' )
elif your _ choice==' scissors ' and my _ choice==' paper ' :
print('youwin!' )
elif your _ choice==' paper ' and my _ choice==' rock ' :
print('youwin!' )
elif your _ choice==' paper ' and my _ choice==' scissors ' 3360
打印(iwin! ' )
elif your _ choice==' rock ' and my _ choice==' scissors ' 3360
print('youwin!' )
elif your _ choice==' scissors ' and my _ choice==' rock ' :
打印(iwin! ' )
again=raw _ input (wouldyouliketoplayagain? ' )
# thisiswhereiwouldliketolooptothestartdependingoninput。
else:
print ('确定,maybe we can play later,bye.' )。
我可以想象,这甚至不是优雅的代码,而是必须用更准确的方法写下我应该做的事情。 如果有时间的话,请给我一些建议。 在
我主要关心的是在每个游戏结束后,如何根据用户的原始输入正确插入循环,然后进入第二个区块,即开始或游戏,或者轻松退出。 在
我非常感谢你的帮助。 在