代码拉取完成,页面将自动刷新
同步操作将从 涛哥专属/PythonGame 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import random
def get_user_choice():
while True:
user_choice = input("请选择(石头/剪刀/布):").lower()
if user_choice in ["石头", "剪刀", "布"]:
return user_choice
else:
print("无效的选择,请重新输入!")
def get_computer_choice():
choices = ["石头", "剪刀", "布"]
return random.choice(choices)
def determine_winner(user_choice, computer_choice):
if user_choice == computer_choice:
return "平局"
elif (
(user_choice == "石头" and computer_choice == "剪刀") or
(user_choice == "剪刀" and computer_choice == "布") or
(user_choice == "布" and computer_choice == "石头")
):
return "用户胜利"
else:
return "电脑胜利"
def play_game():
print("欢迎来到石头剪刀布游戏!")
while True:
user_choice = get_user_choice()
computer_choice = get_computer_choice()
print(f"用户选择:{user_choice}")
print(f"电脑选择:{computer_choice}")
winner = determine_winner(user_choice, computer_choice)
print(f"结果:{winner}")
play_again = input("再玩一局?(是/否):").lower()
if play_again != "是":
break
print("谢谢游玩!")
play_game()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。