python石头剪刀
时间: 2023-08-15 12:13:57 浏览: 55
好的!我来帮你实现一个简单的石头剪刀布游戏。以下是Python代码:
```python
import random
def play_game():
print("欢迎来到石头剪刀布游戏!")
print("请选择:")
print("1. 石头")
print("2. 剪刀")
print("3. 布")
user_choice = int(input("请输入你的选择(1-3):"))
computer_choice = random.randint(1, 3)
choices = ["石头", "剪刀", "布"]
user_choice_name = choices[user_choice - 1]
computer_choice_name = choices[computer_choice - 1]
print(f"你选择了 {user_choice_name}")
print(f"电脑选择了 {computer_choice_name}")
if user_choice == computer_choice:
print("平局!")
elif (user_choice == 1 and computer_choice == 2) or (user_choice == 2 and computer_choice == 3) or (user_choice == 3 and computer_choice == 1):
print("恭喜你,你赢了!")
else:
print("很遗憾,你输了!")
play_game()
```
你可以运行以上代码,然后根据提示输入你的选择(1-3),即可进行石头剪刀布游戏。祝你玩得开心!如果有其他问题,请随时问我。