用户:
Kimi_hjh查看:16 回复:5 评论:16 创建时间:2022-02-22T12:30:58
【作品展示】

【作品介绍】
@9_谁先算到20
【作品源代码】
import turtle
import random
mypen = turtle.Pen()
length = 200
mypen.pensize(40)
mypen.pencolor("lightsalmon")
mypen.forward(length)
mypen.pensize(30)
mypen.pencolor("white")
mypen.backward(length)
total = 0 # 出数总和
while total < 20 :
# 玩家输入整数
myscreen = turtle.Screen()
player_num = int(myscreen.textinput("谁先达到20!","请输入1~3范围的整数:"))
print("玩家出的信息",player_num)
mypen.pencolor("mistyrose")
mypen.forward(player_num * 10)
total = total + player_num
print("总和:",)
if total == 20:
print("玩家赢了!")
elif total > 20:
print("玩家输了!")
else:
# 电脑随机出整数
com_num = random.randint(1 , 3)
print("电脑出的数",com_num)
mypen.pencolor("salmon")
mypen.forward(com_num * 10)
total = total + com_num
print("总和:", total)
if total == 20:
print("电脑赢了!")
elif total > 20:
print("电脑输了!")
else:
print("-----------------")
mypen.hideturtle()
turtle.done()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cnimport time
import turtle
import random
__Pen = turtle.Pen()
time.sleep(1)
a = 0
mypen = turtle.Pen()
length = 200
mypen.pensize(40)
mypen.pencolor('lightsalmon')
mypen.forward(length)
mypen.pensize(30)
mypen.pencolor('white')
mypen.backward(length)
# 出数总和
total = 0
while (total < 20):
# 玩家输入整数
myscreen = turtle.Screen()
try:
player_num = int(turtle.textinput('谁先达到20!', '请输入1~3范围的整数:'))
if (player_num > 3):
print('请输入1~3范围的整数!')
else:
print('玩家出的信息', player_num)
mypen.pencolor('mistyrose')
mypen.forward((player_num * 10))
total = (total + player_num)
print("总和:",total)
if (total == 20):
print('玩家赢了!')
elif (total > 20):
print('玩家输了!')
else:
# 电脑随机出整数
com_num = random.randint(1, 3)
print('电脑出的数', com_num)
mypen.pencolor('salmon')
mypen.forward((com_num * 10))
total = (total + com_num)
print('总和:', total)
if (total == 20):
print('电脑赢了!')
elif (total > 20):
print('电脑输了!')
else:
print('-----------------')
except ValueError:
print('请输入整数!')
mypen.hideturtle()
turtle.done()点赞1
评论
Kimi_hjhimgsrc="https://static.codemao.cn/emotion/thunder_monkey/%E6%91%87%E6%A4%85%E5%AD%90240.gif"alt="emotion_雷电猴_摇椅子"
点赞1
评论
imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E5%8A%A0%E6%B2%B9.gif"alt="emotion_编程猫_加油"
点赞0
评论