随笔 - 1  文章 - 0  评论 - 0  阅读 - 39

Python小练习

2022/04/04 18:41:33

Python小练习

1.绘制一条蟒蛇

复制代码
 1 #snake.py
2 from turtle import * 3 setup(0.8, 0.8, 0, 0) 4 penup() 5 fd(-250) 6 pendown() 7 pensize(25) 8 pencolor("blue") 9 seth(-40) 10 for i in range(3): 11 circle(40, 80) 12 circle(-40, 80) 13 circle(40, 80/2) 14 fd(40) 15 circle(16, 180) 16 fd(40 * 2/3)
复制代码

2.同心圆

复制代码
 1 from turtle import *
 2 a = 10
 3 pencolor("red")
 4 for i in range(0, 5):
 5     penup()
 6     goto(0, -10 * i)
 7     pendown()
 8     circle(a)
 9     a += 10
10 hideturtle()
11 done()
复制代码

3.九九乘法表

1 # 3.九九乘法表
2 print("3.九九乘法表".center(20, '-'))
3 for i in range(1, 10):
4     for j in range(1, i+1):
5         print("{}*{}={:2}".format(j, i, i*j), end=' ')
6     print(' ')

4.1-10的阶乘之和

1 #计算1-10的阶乘之和
2 sum,tmp=0,1
3 for i in range(1,11):
4     tmp*=i
5     sum+=tmp
6 print("运算结果是:{}".format(sum))

5.1-N求和

1 #2.整序列求和
2 print("2.整数序列求和".center(20,'-'))
3 n=eval(input("请输入正整数N:"))
4 sum=0
5 for i in range (int(n)):
6     sum+=i+1
7 print("Sum={}".format(sum))
8 print('-'*40)

6.BMI健康指数

复制代码
 1 height=weight=0.0
 2 g,z="",""
 3 height,weight= eval(input('\r请输入您的身高(m),体重(kg)[用逗号间隔,身高体重都不可为0]:'))
 4 BMI  = float(float(weight)/(float(height)**2))
 5 if BMI <18.5:
 6    g=z="偏瘦"
 7 elif 18.5<= BMI<24:  
 8    g=z="正常"
 9 elif 24<= BMI<25:   
10    g,z="正常","偏胖"
11 elif 25<= BMI <28:    
12    g=z="偏胖"
13 elif 28<=BMI <30:
14     g,z="偏胖","肥胖"
15 else:
16     g=z="肥胖" 
17 print("您的BMI测试结果:\n\tBMI指数:{:.2f}\n\t国际:{}\n\t中国:{}".format(BMI,g,z))
复制代码

7.五角星的绘制

复制代码
1 from turtle import *
2 fillcolor("red")
3 begin_fill()
4 while True:
5     forward(200)
6     right(144)
7     if abs(pos())<1:
8         break
9 end_fill()
复制代码

 

posted on   晤雨  阅读(39)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示