import random
def get_user_choice():
user_input = input("請輸入你的選擇(剪刀,石頭,布):")
while user_input not in ['剪刀', '石頭', '布']:
user_input = input("輸入無效,請重新輸入(剪刀,石頭,布):")
return user_input # 將用戶輸入轉(zhuǎn)換為0、1、2對應(yīng)剪刀、石頭、布
def get_computer_choice():
choices = ['剪刀', '石頭', '布']
return random.choice(choices)
def determine_winner(user_choice, computer_choice):
if (user_choice == '剪刀' and computer_choice == '布') or \
(user_choice == '石頭' and computer_choice == '剪刀') or \
(user_choice == '布' and computer_choice == '石頭'):
return "你贏了!"
elif user_choice == computer_choice:
return "平局!"
else:
return "電腦贏了!"
def main():
while True:
print("歡迎來到剪刀石頭布游戲!")
user_choice = get_user_choice()
computer_choice = get_computer_choice()
print("你出了:", user_choice)
print("電腦出了:", computer_choice)
result = determine_winner(user_choice, computer_choice)
print(result)
if __name__ == "__main__":
main()

var code = "2973e38e-012f-443f-aa57-bb0e11ea9702"
浙公網(wǎng)安備 33010602011771號