#实现一个剪刀、石头、布的游戏,首先使用 random
模块的函数从列表 ['剪刀', '石头', '布']
中随机选择一个,然后机器人玩家也随机出一个,比较两个,判断#玩家是输是赢。最后给出机器人玩家赢了几次,输了几次,平了几次。
#提示:从列表 '剪刀', '石头', '布']
随机选择,可以使用 random.choice(['剪刀', '石头', '布']
import random
#总测试次数
x = 10
#玩家赢的次数
wins = 0
#玩家输的次数
bads = 0
#玩家平的次数
evens = 0
while x>0:
robot = random.choice(['剪刀', '石头', '布'])
player = random.choice(['剪刀', '石头', '布'])
print(f'robot show {robot}, player show {player}', end="")
if(robot==player):
evens += 1
print(f" player and robot are even! 平手了{evens}次")
elif(robot=="剪刀" and player=="布" ):
wins += 1
print(f"________robot is win! times:{wins}")
elif(robot=="布" and player=="石头" ):
wins += 1
print(f"________robot is win! times:{wins}")
elif(robot=="石头" and player=="剪刀" ):
wins += 1
print(f"________robot is win! times:{wins}")
else:
bads += 1
print(f" robot is bad! times:{bads}")
x-=1
print("Done!")