用户:Box3训练师MAX查看:0 回复:1 评论:0 创建时间:2021-06-25T23:08:47
【作品展示】

【作品介绍】
数字1是剪刀数字2是石头
数字3是布
看看你是否能战胜电脑,取得胜利呢?
【作品源代码】
import turtle
import random
myscreen = turtle.Screen()
mypen = turtle.Pen()
mypen.hideturtle()
mypen.penup()
mypen.goto(-122.5,0)
mypen.pendown()
count = 0
p_win = 0
c_win = 0
flag = False
while count < 10:
player = int(myscreen.textinput("剪刀1-石头2-布3","请输入拳名对应的数字:"))
if player < 1 or player > 3:
count = count + 1
computer = random.randint(1,3)
if player == 1:
print("玩家出了:剪刀")
elif player == 2:
print("玩家出了:石头")
elif player == 3:
print("玩家出了:布")
else:
print("玩家输入数字超出范围")
flag = True
if computer == 1:
print("计算机出了:剪刀")
elif computer == 2:
print("计算机出了:石头")
else:
print("计算机出了:布")
#判断胜负
if player == computer or flag:
print("此局是平局或废局")
mypen.pencolor("gray")
mypen.dot(20)
flag = False
elif player == 1 and computer == 3 or player == 2 and computer == 1 or player == 3 and computer == 2:
print("此局玩家胜")
p_win = p_win + 1
mypen.pencolor("darkgreen")
mypen.dot(20)
elif player == 3 and computer == 1 or player == 1 and computer == 2 or player == 2 and computer == 3:
print("此局计算机胜")
c_win = c_win + 1
mypen.pencolor("red")
mypen.dot(20)
mypen.penup()
mypen.forward(25)
mypen.pendown()
count = count + 1
print("---------------")
print("玩家的胜局为:",p_win)
print("计算机的胜局为:",c_win)
turtle.done()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn