用户:神经蛙box3查看:0 回复:2 评论:0 创建时间:2021-10-07T16:41:45
【作品展示】

【作品介绍】
计算机说第44行错了有没有大佬来解答啊喂
【作品源代码】
import random
import turtle
# 电脑
print('欢迎来到计算机')
while True:
a = input('有什么事吗 1=计算 2=游戏 ')
# 计算
if a == '1':
print('好的,正在加载...')
b = eval(input('第一个数是什么? '))
c = eval(input('第二个呢? '))
d = input('什么运算 1=加 2=减 3=乘 4 =除 ')
if d == '1':
print(b + c)
elif d == '2':
print(b - c)
elif d == '3':
print(b * c)
else:
print(b / c)
# 游戏
if a == '2':
e = input('玩什么游戏?1=猜数 2=图画 3= 画画')
# 猜数
if e == '1':
print('好的,正在加载...')
f = random.randrange(1, 15)
print('我们来玩')
while True:
g = eval(input('数是什么? '))
if g > f:
print('大了')
elif g < f:
print('小了')
else:
print('对了')
h = input('你还想玩吗?1=想 2=不了 ')
if h == '1':
pass
else:
break
# 图画
elif a == '2':
__Pen = turtle.Pen()
# 分形樱花树
def tree(branchLen, t):
if (branchLen > 3):
if (8 <= branchLen and branchLen <= 12):
if (random.randint(0, 2) == 0):
t.pencolor('snow')
else:
t.pencolor('lightcoral')
t.pensize((branchLen / 3))
elif (branchLen < 8):
if (random.randint(0, 1) == 0):
t.pencolor('snow')
else:
t.pencolor('lightcoral')
t.pensize((branchLen / 2))
else:
t.pencolor('sienna')
t.pensize((branchLen / 10))
t.forward(branchLen)
a = (1.5 * (random.random()))
t.right((20 * a))
b = (1.5 * (random.random()))
tree(branchLen - 10 * b, t)
t.left((40 * a))
tree(branchLen - 10 * b, t)
t.right((20 * a))
t.penup()
t.backward(branchLen)
t.pendown()
# 绘制树下花瓣,参数分别是画板数、画笔
def petal(m, t):
for i in range(m):
a = (200 - 400 * (random.random()))
b = (10 - 20 * (random.random()))
t.penup()
t.forward(b)
t.left(90)
t.forward(a)
t.pendown()
t.pencolor('lightcoral')
t.circle(1)
t.penup()
t.backward(a)
t.right(90)
t.backward(b)
def main():
t = turtle.Pen()
__Pen.hideturtle()
t.speed(0)
turtle.bgcolor('wheat')
t.left(90)
t.penup()
t.backward(150)
t.pendown()
t.pencolor('sienna')
tree(60, t)
petal(100, t)
turtle.done()
main()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn
Python-happyyyyimport random
import turtle
# 电脑
print('欢迎来到计算机')
while True:
a = input('有什么事吗 1=计算 2=游戏 ')
# 计算
if a == '1':
print('好的,正在加载...')
b = eval(input('第一个数是什么? '))
c = eval(input('第二个呢? '))
d = input('什么运算 1=加 2=减 3=乘 4 =除 ')
if d == '1':
print(b + c)
elif d == '2':
print(b - c)
elif d == '3':
print(b * c)
else:
print(b / c)
exit()
# 游戏
if a == '2':
e = input('玩什么游戏?1=猜数 2=图画 3= 画画')
# 猜数
if e == '1':
print('好的,正在加载...')
f = random.randrange(1, 15)
print('我们来玩')
while True:
g = eval(input('数是什么? '))
if g > f:
print('大了')
elif g < f:
print('小了')
else:
print('对了')
h = input('你还想玩吗?1=想 2=不了 ')
if h == '1':
pass
else:
break
# 图画
elif a == '2':
__Pen = turtle.Pen()
def tree(branchLen, t):
if branchLen > 3:
if 8 <= branchLen <= 12:
if random.randint(0, 2) == 0:
t.pencolor('snow')
else:
t.pencolor('lightcoral')
t.pensize((branchLen / 3))
elif branchLen < 8:
if random.randint(0, 1) == 0:
t.pencolor('snow')
else:
t.pencolor('lightcoral')
t.pensize((branchLen / 2))
else:
t.pencolor('sienna')
t.pensize((branchLen / 10))
t.forward(branchLen)
a = (1.5 * (random.random()))
t.right((20 * a))
b = (1.5 * (random.random()))
tree(branchLen - 10 * b, t)
t.left((40 * a))
tree(branchLen - 10 * b, t)
t.right((20 * a))
t.penup()
t.backward(branchLen)
t.pendown()
# 绘制树下花瓣,参数分别是画板数、画笔
def petal(m, t):
for i in range(m):
a = (200 - 400 * (random.random()))
b = (10 - 20 * (random.random()))
t.penup()
t.forward(b)
t.left(90)
t.forward(a)
t.pendown()
t.pencolor('lightcoral')
t.circle(1)
t.penup()
t.backward(a)
t.right(90)
t.backward(b)
def main():
t = turtle.Pen()
t.hideturtle()
t.speed(0)
turtle.bgcolor('wheat')
t.left(90)
t.penup()
t.backward(150)
t.pendown()
t.pencolor('sienna')
tree(60, t)
petal(100, t)
turtle.done()
main()
点赞0
评论