猜拳游戏
import random
player_input
=input("请输入(0剪刀,1石头,2布):")
player
=int(player_input
)
computer
=random
.randint
(0,2)
if(player
==0 and computer
==2) or (player
==1 and computer
==0) or (player
==2 and computer
==1):
print("电脑出的是%s,恭喜,你赢了!"%computer
)
elif(player
==0 and computer
==0) or (player
==1 and computer
==1) or (player
==2 and computer
==2):
print("电脑出的是%s,打成了平局"%computer
)
else:
print("电脑出的是%S,你输了!"%computer
)
通过本代码我们可以进而写出猜筛子游戏,通过电脑给玩家随机给出的数字与电脑随机出一个数字进行比较。
猜筛子游戏
import random
player
=random
.randint
(1,6)
print("你的筛子摇出了%s"%player
)
computer
=random
.randint
(1,6)
if(player
>computer
):
print("电脑出的是%s,你赢了!"%computer
)
elif(player
==computer
):
print("电脑出的是%s,打成了平局"%computer
)
else:
print("电脑出的是%s,你输了!"%computer
)
import random
num
=random
.randint
(a
,b
)
print(num
)***
转载请注明原文地址:https://tech.qufami.com/read-18992.html