python石头剪刀布
时间: 2023-06-29 14:20:30 浏览: 50
好的,我可以为您提供一个简单的 Python 石头剪刀布游戏。您可以试试以下代码:
```python
import random
while True:
# 让用户输入选择
user_choice = input("选择石头、剪刀或布 (输入 q 退出游戏): ")
if user_choice == 'q':
break
# 计算电脑的选择
computer_choice = random.choice(['石头', '剪刀', '布'])
# 输出电脑的选择
print(f"电脑选择了 {computer_choice}.")
# 判断胜负
if user_choice == computer_choice:
print("平局!")
elif user_choice == '石头' and computer_choice == '剪刀':
print("你赢了!")
elif user_choice == '剪刀' and computer_choice == '布':
print("你赢了!")
elif user_choice == '布' and computer_choice == '石头':
print("你赢了!")
else:
print("你输了!")
```
这个代码让用户输入自己的选择,然后计算电脑的选择,并判断胜负。您可以尝试运行一下,看看效果。