猜拳游戏1.0
"""
石头1 布2 剪刀3
我们赢
电脑 我们 结果
1 2 -1
2 3 -1
3 1 2
我们输
电脑 我们 结果
1 3 -2
2 1 1
3 2 1
我们平局
电脑 我们 结果
1 1 0
2 2 0
3 3 0
"""
import random
computer = random.randint(1,3)
we = input("请出拳(石头1 布2 剪刀3)")
we = int(we)
result = computer - we
if result == -1 or result == 2:
print("你赢了!!!!!!!!!!!!!!!")
print("电脑出了%d"%computer)
print("我们出了%d"%we)
猜拳游戏2.0
import random
win = 0
for i in range(20):
computer = random.randint(1,3)
we = input("请出拳(石头1 布2 剪刀3)")
we = int(we)
jie_guo = computer - we
if 1<=we<=3:
if jie_guo == -1 or jie_guo == 2:
print("你赢了!!!!!!!!!!!!!!!")
win = win +1
elif jie_guo ==1 or jie_guo ==-2:
print("你输了,请再来一局。")
else:
print("平局")
else:
print("你犯规了")
print("shanzhi猜拳,你赢了%d局"%win)
猜拳游戏3.0
import random
win = 0
lose = 0
a = 0
we = input("请出拳(石头1 布2 剪刀3)")
for i in we:
i = int(i)
computer = random.randint(1,3)
jie_guo = computer - i
if 1<=i<=3:
if jie_guo == -1 or jie_guo == 2:
print("你赢了!!!!!!!!!!!!!!!")
win = win +1
elif jie_guo ==1 or jie_guo ==-2:
print("你输了,请再来一局。")
lose = lose + 1
else:
a = a+1
print("平局")
else:
print("你犯规了")
print("shanzhi猜拳,你一共玩了%d局"%len(we))
print("shanzhi猜拳,你赢了%d局"%win)
print("shanzhi猜拳,你输了%d局"%lose)
print("shanzhi猜拳,你平了%d局"%a)