美文网首页
Python程序

Python程序

作者: 数学笔记分享 | 来源:发表于2021-03-15 10:49 被阅读0次

>>> r = 25

>>> area = 3.1415 * r * r

>>> print(area)1963.4375000000002

>>> print(" {:.2f}".format(area))1963.44

import turtle

for i in range(3):

    turtle.seth(i*120)

    turtle.fd(100)

num = 414//23

number = input('猜一猜414//23的运行结果吧')

times = 1

while True:

  if times > 2:

    break

  if number.isnumeric():

    if int(number) == num:

      break

    if int(number) > num:

      number = input('不对哦,猜大了')

    else:

      number = input('不对哦,猜小了')

  else:

    number = input('需要在下方输入数字')

  times += 1

if times > 2 and int(number) != num:

  print('三次机会用完了')

else:

  print('恭喜你猜中了')

print('结果是' + str(num))

画心

import turtle

def curvemove():

  for i in range(200):

    turtle.right(1)

    turtle.forward(1)

turtle.color('red')

turtle.begin_fill()

turtle.left(140)

turtle.forward(111.65)

curvemove()

turtle.left(120)

curvemove()

turtle.forward(111.65)

turtle.end_fill()

turtle.penup()

turtle.goto(-40, -50)

turtle.pendown()

turtle.write('',  font = ('SimHei', 15, 'bold'))

turtle.hideturtle()

绘制圣诞树

import turtle

screen = turtle.Screen()

screen.setup(375,700)

circle = turtle.Turtle()

circle.shape('circle')

circle.color('red')

circle.speed('fastest')

circle.up()

square = turtle.Turtle()

square.shape('square')

square.color('green')

square.speed('fastest')

square.up()

circle.goto(0,280)

circle.stamp()

k = 0

for i in range(1, 13):

    y = 30*i

    for j in range(i-k):

        x = 30*j

        square.goto(x,-y+280)

        square.stamp()

        square.goto(-x,-y+280)

        square.stamp()

    if i % 4 == 0:

        x =  30*(j+1)

        circle.color('red')

        circle.goto(-x,-y+280)

        circle.stamp()

        circle.goto(x,-y+280)

        circle.stamp()       

        k += 3

    if i % 4 == 3:

        x =  30*(j+1)

        circle.color('yellow')

        circle.goto(-x,-y+280)

        circle.stamp()

        circle.goto(x,-y+280)

        circle.stamp()

square.color('brown')

for i in range(13,17):

    y = 30*i

    for j in range(2):   

        x = 30*j

        square.goto(x,-y+280)

        square.stamp()

        square.goto(-x,-y+280)

        square.stamp()       

       

text = turtle.Turtle()

text.hideturtle()

text.penup()

text.goto(-120, 270)

text.color('red')

text.write('圣诞快乐', font = ('SimHei', 18, 'bold'))

#可以把【圣诞快乐】换成你的祝福语哦~

相关文章

网友评论

      本文标题:Python程序

      本文链接:https://www.haomeiwen.com/subject/zmntcltx.html