当前位置:网站首页>Some examples.
Some examples.
2022-06-29 07:39:00 【Rookie 1!!】
1、
Exchange rate conversion procedure . According to the design idea of temperature conversion program , according to 1 dollar =6 RMB remittance
Write a two-way exchange program between US dollars and RMB .
MoneyStr = input(" Please enter the amount with the symbol :")
if MoneyStr[-1] in [' dollar ','d']:
C = (eval(MoneyStr[0:-1]) ) * 6
print(" The amount converted into RMB is {:.2f} RMB " .format(C))
elif MoneyStr[-1] in [' RMB ',' element ']:
F = eval(MoneyStr[0:-1] ) / 6
print(" The temperature after conversion is {:.2f} dollar " .format(F))
else:
print(" Input format error ")
2、
example 2 Modification of . Transformation instance code 2.1, Draw a colored python , That is, when drawing Python
Each segment of a python , The paint color of the brush will change .
Tips : Put the brush color control function near the python drawing function .
#a2.3DrawPython.py
import turtle
turtle.setup(650,350,200,200)
turtle.penup()
turtle.fd(-250)
turtle.pendown()
turtle.pensize(25)
turtle.pencolor("green")
turtle.seth(-40)
for i in range(4):
turtle.circle(40,80)
turtle.pencolor("purple")
turtle.circle(-40,80)
turtle.pencolor("yellow")
turtle.pencolor("black")
turtle.circle(40, 80/2)
turtle.fd(40)
turtle.circle(16,180)
turtle.fd(40 * 2/3)

3、
Drawing of equilateral triangle . Use turtle In the library turtle.fd0 Sum of two numbers turtle.setho Function drawing
Make an equilateral triangle , The effect is shown in the figure .
#e2.1DrawTriangle.py
import turtle
turtle.setup(650,550,2,100)
turtle.fd(250)
turtle.penup()
turtle.seth(120)
turtle.pendown()
turtle.fd(250)
turtle.penup()
turtle.seth(-120)
turtle.pendown()
turtle.fd(250)

4、
Drawing of superimposed equilateral triangles . Use turtle In the library turtle.fd0 Functions and turtle.seth0 Letter
Number to draw a superimposed equilateral triangle , The effect is shown in the figure .
#e2.5DrawTriangle.py
import turtle
turtle.setup(650,550,2,100)
turtle.fd(200)
turtle.seth(120)
turtle.fd(200)
turtle.seth(-120)
turtle.fd(100)
turtle.seth(0)
turtle.fd(100)
turtle.seth(-120)
turtle.fd(100)
turtle.seth(120)
turtle.fd(100)
turtle.seth(-120)
turtle.fd(100)

5、
Drawing of a square without corners . utilize turtle The library function draws a square without corners , The effect is like
As shown in the figure .
#e2.6DrawSquare.py
import turtle
turtle.setup(600,820,2,100)
turtle.fd(200)
turtle.penup()
turtle.fd(60)
turtle.seth(90)
turtle.fd(60)
turtle.pendown()
turtle.fd(200)
turtle.penup()
turtle.fd(60)
turtle.seth(180)
turtle.fd(60)
turtle.pendown()
turtle.fd(200)
turtle.penup()
turtle.fd(60)
turtle.seth(270)
turtle.fd(60)
turtle.pendown()
turtle.fd(200)
6、
Drawing of hexagon . utilize turtle Library draw a hexagon , The effect is shown in the figure .
import turtle
turtle.setup(650,400,200,200)
turtle.seth(30) # The starting direction of the brush
for i in range(6):
turtle.fd(60) # Hexagonal side length 30
turtle.left(120) # Move counterclockwise 120 degree
turtle.fd(60)
turtle.left(120)
turtle.fd(60)
turtle.left(120) # Draw a triangle
turtle.fd(60)
turtle.right(60) # Change direction , Start preparing new triangles

7、
Drawing of square helix . utilize turtle Library draw a square helix , The effect is as shown in the picture .
import turtle
turtle.setup(650,400,200,200)
turtle.seth(90) # The starting direction of the brush
a=0
for i in range(25):
a = a+5
turtle.fd(a)
turtle.left(90)
turtle.fd(a+5)
turtle.left(90)
turtle.fd(a+5)
turtle.left(90)
turtle.fd(a+10)
turtle.left(90)
a = a+5

边栏推荐
猜你喜欢

Concurrent idempotent anti shake

excel高级绘图技巧100讲(六)-甘特图在项目进度上的实战应用案例

Kingbasees v8r6 cluster maintenance case -- single instance data migration to cluster case

What you should know about databases

施努卡:什么是视觉定位系统 视觉定位系统的工作原理

IMX6DL4.1.15支持EIM总线(下)——配置原理分析。
![[translation] E-Cloud. Large scale CDN using kubeedge](/img/ac/178c078589bb5bc16dbdc8f4ae9525.png)
[translation] E-Cloud. Large scale CDN using kubeedge

ShapeShifter: Robust Physical Adversarial Attack on Faster R-CNN Object Detector

【工控老马】西门子PLC s7-300SCL编程详解

Mmclassification installation and debugging
随机推荐
Alicloud access resource: nosuchkey
[translation] swarmed out. Design methods for building modern applications
Final summary spark
【科普资料】从科学精神到科学知识的材料
Markdown skill tree (9): tables
详解Autosar Arxml中的CANFD报文及格式
服装行业的CRM品牌供应商如何选型?
1031 Hello World for U
Schnuka: 3D visual recognition system 3D visual inspection principle
358. K 距离间隔重排字符串 排序
Check whether tensorflow supports GPU and test program
施努卡:3d机器视觉检测系统 3d视觉检测应用行业
How to talk about salary correctly in software test interview?
E-commerce is popular, how to improve the store conversion rate?
101. 对称二叉树(递归与迭代方法)
Two ways to write throttling - recently seen
蓝桥杯——最小框架
Schnuka: 3D visual inspection scheme 3D visual inspection application industry
SAP ui5 Beginner (I) Introduction
uva10859