pyton石头剪刀布人机对垒from turtle import * color("red", "yellow") bgcolor('azure') pensize(10) pencolor("yellow") goto(0,100) color("yellow","pink") begin_fill() circle(30) end_fill() goto(0,0)#原点出发 goto(-70,-70)#一条条腿 goto(0,0)#返回原点出发 goto(70,-70) goto(0,0) goto(0,0) goto(40,75) pencolor("pink") goto(40,90) goto(40,75) pencolor("yellow") goto(0,50) goto(-40,25) pencolor("pink") goto(-40,10) hideturtle() done()
时间: 2023-06-02 21:03:51 浏览: 75
这段代码是用Python写的一个石头剪刀布游戏,采用了Python中的turtle模块来实现可视化。代码中先设置了画笔的颜色、大小和背景色,然后用turtle模块提供的goto()函数移动画笔到指定位置、选择颜色并进行填充,最后将画笔移动到屏幕中心。
相关问题
pyton石头剪刀布人机对垒代码
好的,下面是Python实现的石头剪刀布人机对垒代码:
```
import random
# 定义石头剪刀布的列表
gesture = ['石头', '剪刀', '布']
# 取玩家的输入
player = input("请输入石头, 剪刀, 布:")
# 取电脑的输入
computer = random.choice(gesture)
# 输出电脑的选择
print("电脑选择了:", computer)
# 判断胜负
if player == computer:
print("平局")
elif player == '石头' and computer == '剪刀' \
or player == '剪刀' and computer == '布' \
or player == '布' and computer == '石头':
print("你赢了")
else:
print("电脑赢了")
```
希望对你有帮助!如果有其他问题,欢迎继续提问。
pyton石头剪刀布人机对垒代码五局三胜
好的,以下是五局三胜的Python石头剪刀布代码:
```
import random
# 人机对垒
def game(player,computer):
if player == computer:
print("平局,再来一局!")
return 0
elif (player == '石头' and computer == '剪刀') or (player == '剪刀' and computer == '布') or (player == '布' and computer == '石头'):
print("你赢了这局!")
return 1
else:
print("电脑赢了这局!")
return -1
# 主函数
if __name__ == '__main__':
win = 0
total = 0
while win < 3 and total < 5:
print("\n第{}局开始:".format(total+1))
player_hand = input("请出拳:(石头/剪刀/布)")
while player_hand not in ['石头', '剪刀', '布']:
player_hand = input("请出拳:(石头/剪刀/布)")
computer_hand = random.choice(['石头', '剪刀', '布'])
print("电脑出:", computer_hand)
result = game(player_hand, computer_hand)
if result == 1:
win += 1
elif result == -1:
win = 0
total += 1
if win == 3:
print("你赢了五局三胜的比赛!")
else:
print("电脑赢了五局三胜的比赛!")
```
希望能帮到你,如果有其他问题需要解答,请继续提问。
阅读全文