当前位置:网站首页>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

边栏推荐
- ShapeShifter: Robust Physical Adversarial Attack on Faster R-CNN Object Detector
- 1031 Hello World for U
- jmeter 用beanshell导入自己jar包老是查找不到
- Dump (cl\alv\tree\base================================cp|set\items\for\column) when expanding node or clicking toolbar button
- TREE ALV 展开Node或者点击Toolbar按钮时DUMP(CL_ALV_TREE_BASE==============CP|SET_ITEMS_FOR_COLUMN)
- 软件测试面试如何正确谈论薪资?
- 服裝行業的CRM品牌供應商如何選型?
- 1032 Sharing
- tf. count_ nonzero
- 帆船动力学仿真分析
猜你喜欢

【工控老马】基于PLC的花样喷泉设计原理详解

1183:病人排队

matlab 多普勒效应产生振动信号和处理

cv2.cvtColor
![[translation] E-Cloud. Large scale CDN using kubeedge](/img/ac/178c078589bb5bc16dbdc8f4ae9525.png)
[translation] E-Cloud. Large scale CDN using kubeedge

感知健康生活 赋能无界连接 ——为OpenHarmony 3.1生态构建贡献芯海力量

Kyushu cloud helps Inner Mongolia's "counting from the east to the west" project to drive the smart new ecology of the surveying and mapping industry

Listen to textarea input through Keyup to change button style

ES中配置ext.dic文件不生效的原因

A hybrid model of machine learning notes time series
随机推荐
tf.to_int64
TF.Slim的repeat和stack操作
KingbaseES 中select distinct on 语句
498. 对角线遍历(模拟)
【工控老马】西门子PLC s7-300SCL编程详解
蓝桥杯——13届第二批试题解析
Use of parameter in Simulink for AUTOSAR SWC
虚拟DOM真的是最快的吗?
What tools do testers need to know
Kingbasees v8r6 cluster maintenance case - data migration between clusters
Schnuka: automatic tire grabbing installation, 3D visual positioning, automatic robot grabbing
施努卡:3D视觉识别系统 3D视觉检测原理
Blue Bridge Cup -- Analysis of the second batch of test questions of the 13th session
A hybrid model of machine learning notes time series
帆船动力学仿真分析
1032 Sharing
施努卡:视觉定位系统厂家 什么是视觉定位系统
路由详解(九阳真经)
Markdown skill tree (7): separator and reference
[popular science materials] materials from scientific spirit to scientific knowledge