Python石头剪刀布游戏
通过运用random库产生随机数和判断结构形成石头剪子布游戏,快来试试吧!
- from random import randint
- while True:
-
x=randint(1,3)
-
if x==1:
-
ID="石头"
-
if x==2:
-
ID="剪子"
-
if x==3:
-
ID="布"
-
man=input("请输入你出的拳:")
-
list=["石头","剪子","布"]
-
if(man not in list):
-
print("输入有误,请重试!")
-
elif man==ID:
-
print("计算机出了:"+ID+"平局!")
-
elif (man=="石头"and ID=="剪子")or(man=="剪子"and ID=="布")or(man=="布"and ID=="石头"):
-
print("计算机出了:"+ID+"你赢了!")
-
elif (ID=="石头"and man=="剪子")or(ID=="剪子"and man=="布")or(ID=="布"and man=="石头"):
-
print("计算机出了:"+ID+"你输了!")