turtle square drawing
describe
Using the turtle library, draw a square.
NOTE: This is not an auto-graded question, it is for practice only, and is not graded.
output example
The square effect is as follows:
Code: Mr. Songtian on Mooc, the speech is very clear and clear, let's write it directly, square, loop four times, first draw a 100-pixel straight line, and turn the pen 90 degrees each time. Just a square.
# print square import turtle turtle.setup(650,350) turtle.pecolor("purple") for i in range(4): turtle.fd(100) turtle.left(90)
turtle hexagon drawing
describe
Using the turtle library, draw a hexagon.
NOTE: This is not an auto-graded question, it is for practice only, and is not graded.
output example
The hexagon effect is as follows:
Code: Loop six times, first draw 100 pixels each time, and then turn left 60 degrees, because of the hexagon, each inner angle is 120, and the outer angle is 180-120=60. The rotation is the current angle of this point.
#print hexagram import turtle as t t.setup(600,600) for i in range(6): t.fd(100) t.left(60)
turtle overlapping edge drawing
describe
Using the turtle library, draw a stacked polygon, where the inner angle of the stacked polygon is 80 degrees.
NOTE: This is not an auto-graded question, it is for practice only, and is not graded.
output example
The overlapping edge effect is as follows:
Code:
#Draw the overlapping edge effect import turtle as t t.setup(600,600) for i in range(7): t.fd(100) t.left(80)
turtle draws with tangent circle
describe
Using the turtle library, draw a tangent circle.
NOTE: This is not an auto-graded question, it is for practice only, and is not graded.
output example
The effect of the same tangent circle is as follows:
Code: increment the radius of the rotation by 30 pixels each time
#draw the same cut garden import turtle as t t.setup(600,600) for i in range(4): t.circle(50+i*30)
length conversion I
describe
Please write a program to complete the length conversion between meters and inches. The basic requirements are as follows:
Enter inches, convert to meters;
Enter meters to convert to inches.
Inches are marked with in and placed at the end of the value; meters are marked with m and placed at the end of the value.
1 meter = 39.37 inches
Please use input() for input parameters, do not add prompt string information.
input format
Example 1: 10m
Example 2: 20in
output format
The same as the input format, the output result retains 3 decimal places.
Example of input and output
enter | output | |
Example 1 | |
|
代码:输入的时候判读最后一个字母是m的话就就是米转换英尺,按照题目给的计算公式计算,其余情况都按照英尺转换米计算。
#长度转换 I a=input() if(a[-1])=='m': ans=eval(a[0:-1])*39.37 print("{:.3f}in".format(ans)) else: ans=float(eval(a[0:-2]))/39.37 print("{:.3f}m".format(ans))