新人不会做
python3吧
全部回复
仅看楼主
level 1
求解大哥们
2025年03月22日 15点03分 1
吧务
level 12
贴吧就图一乐,这种题问ai都比问吧友来的快多了[小乖][小乖]
2025年03月22日 15点03分 2
主要是这个还是简单的[呵呵]初学者还是不要想着求助,自己动动手吧[挖鼻][懒得理]
2025年04月24日 12点04分
level 1
import random
# 设置随机种子,保证每次生成的随机数一致
random.seed(12345)
def get_computer_choice():
# 随机生成 0, 1, 2 来代表 石头、剪刀、布
return random.randint(0, 2)
def get_user_choice():
while True:
user_input = input("请输入你的选择(0: 石头, 1: 剪刀, 2: 布):")
if user_input in ['0', '1', '2']:
return int(user_input)
else:
print("无效输入,请重新输入(0: 石头, 1: 剪刀, 2: 布)")
def determine_winner(user_choice, computer_choice):
if user_choice == computer_choice:
return "平局"
elif (user_choice == 0 and computer_choice == 1) or (user_choice == 1 and computer_choice == 2) or (user_choice == 2 and computer_choice == 0):
return "用户获胜"
else:
return "计算机获胜"
# 游戏主循环
user_wins = 0
computer_wins = 0
while True:
user_choice = get_user_choice()
computer_choice = get_computer_choice()
print(f"用户选择: {user_choice},计算机选择: {computer_choice}")
winner = determine_winner(user_choice, computer_choice)
print(f"结果: {winner}")
if winner == "用户获胜":
user_wins += 1
elif winner == "计算机获胜":
computer_wins += 1
print(f"当前得分 - 用户: {user_wins} 计算机: {computer_wins}")
# 判断是否有一方获胜超过2次
if user_wins > 2:
print("恭喜!用户胜利!")
break
elif computer_wins > 2:
print("计算机胜利!")
break
2025年04月10日 05点04分 3
level 2
看不清
2025年04月21日 18点04分 4
1