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

边栏推荐
- 详解Autosar Arxml中的CANFD报文及格式
- Schnuka: automatic tire grabbing installation, 3D visual positioning, automatic robot grabbing
- [popular science materials] materials from scientific spirit to scientific knowledge
- tf.to_int64
- Swin Transformer理论讲解
- 机器学习笔记 - 时间序列的混合模型
- Machine learning notes - time series prediction using machine learning
- 部署Prometheus-server服务 system管理
- Appium 环境搭建
- 九州云助力内蒙古“东数西算”工程,驱动测绘行业智慧新生态
猜你喜欢
How to view software testing training? Do you need training?

1032 Sharing

1183:病人排队
![[FreeRTOS] interrupt mechanism](/img/ab/9b1d07048b4631d7cc95db99ed529a.png)
[FreeRTOS] interrupt mechanism

1183: patient queue

tf.count_nonzero

TREE ALV 展开Node或者点击Toolbar按钮时DUMP(CL_ALV_TREE_BASE==============CP|SET_ITEMS_FOR_COLUMN)

ShapeShifter: Robust Physical Adversarial Attack on Faster R-CNN Object Detector
What tools do testers need to know

Appium自动化测试基础 — ADB常用命令(三)
随机推荐
Markdown skill tree (7): separator and reference
tf.to_int64
施努卡:视觉定位系统厂家 什么是视觉定位系统
How to solve the cross domain problem of mobile phone accessing the web in the web development scenario
Markdown skill tree (3): title
tf. compat. v1.assign
How to authorize subordinates?
1032 Sharing
tf. count_ nonzero
498. 对角线遍历(模拟)
帆船动力学仿真分析
Autosar SWC在Simulink中Parameter的使用
tf.compat.v1.assign
tf. to_ int64
358. K 距离间隔重排字符串 排序
施努卡:轮胎自动抓取安装,3D视觉定位,机器人自动抓取
部署Prometheus-server服务 system管理
Using cdockablepane to realize floating window in MFC
Vibration signal generation and processing based on MATLAB Doppler effect
九州云助力内蒙古“东数西算”工程,驱动测绘行业智慧新生态