# 用循环进行游戏
while True:
if i == 0:
# 设置一个字符串变量start,作为游戏开始的判断
start = input("是否开始游戏(是y/否n):")
else:
start = input("是否再来一局(是y/否n):")
# 输入的若非y,Y,n,N,则重新输入,直至正确
if start != "y" and start != "Y" and start != "n" and start != "N":
print("输入错误,请重新输入")
start = input("是否开始游戏(是y/否n):")
# 若输入的是n,N,则游戏结束,跳出整个游戏循环
elif start == "n" or start == "N":
print("游戏结束")
break
# 若输入的是y,Y,则游戏开始
elif start == "y" or start == "Y":
if i == 0:
print("游戏开始")
else:
print("游戏继续")
while True:
# 从控制台输入要出的拳,1表示石头,2表示剪刀,3表示布
player = input("请出拳(1表示石头,2表示剪刀,3表示布):")
# 将输入的数字以汉字的形式输出,更为直观
if player == "1" or player == "2" or player == "3":
if player == "1":
player_str = "石头"
elif player == "2":
player_str = "剪刀"
elif player == "3":
player_str = "布"
break
else:
print("输入错误,请重新输入")