2-a to draw a pentagram with circulation
Import Turtle for in range (5): turtle.forward ( turtle.left) (144)
2-b to draw concentric circles with loops
Import Turtleturtle.color ('red') for in range (4): turtle.up () turtle.goto (0,-40* (i+1)) Turtle.down () Turtle.circle (40* (i+1))
2-c using while loop to draw the sun flower
from Import *color ('red','yellow') begin_ Fill () while True: forward ($) left ( in) If abs (POS ()) <1: breakEnd_fill () done ()
2-d five pentagram with function definition
ImportTurtleturtle.bgcolor ('Red') Turtle.color ('Yellow') Turtle.fillcolor ('Yellow')defGuo_goto (x, y): Turtle.up () Turtle.goto (x, y) turtle.down ()defGuo_draw (x): Turtle.begin_fill () forIinchRange (5): Turtle.forward (x) turtle.right (144) Turtle.end_fill () Guo_goto (-300,200) Guo_draw (170) Guo_goto (30,280) Guo_draw (60) Guo_goto (120,200) Guo_draw (60) Guo_goto (120,126) Guo_draw (60) Guo_goto (30,60) Guo_draw (30L
2-e The sun Flower of a diamond petal with a function definition
ImportTurtledefDraw_diamond (Brad): Brad.forward (100) Brad.right (45) Brad.forward (100) Brad.right (135)defdraw_art (): Window=Turtle. Screen () Window.bgcolor ("Purple") Brad=Turtle. Turtle () Brad.shape ("Turtle") Brad.color ("Orange") Brad.speed ("fastest") forIinchRange (1,37): Draw_diamond (Brad) Draw_diamond (Brad) Brad.left (10) Brad.right (90) Brad.pensize (5) Brad.color ('Green') Brad.forward (300) Window.exitonclick () Draw_art ()
3-a input number, identify grade, major, serial number.
S=input ("Pleaseinput your Student number:")print(" grade is ", S[:4])print(" Professional Yes ", S[4:6]) Print(" serial number is ", S[-3:])
3-b Enter a number of 1-7 to output the corresponding "Day of the Week".
A=' Monday Tuesday Wednesday Thursday Friday Saturday Sunday 'd=int ('1-7:' )Print(a[3* (d-1): 3*d])
3-c identify the provincial, age, and gender of the identity card number.
Id=input ('Please enter 18-digit ID number:')ifLen (ID) ==18: Print("your ID number is."+ID)Else: Print("Wrong ID number") Id_add=id[0:6]id_birth=id[6:10]id_sex=id[14:17]ifInt (id_add) ==440101: Print("Province City: Guangzhou district of Guangdong province")elifInt (id_add) ==440102: Print("Province City: Dongshan District, Guangzhou, Guangdong province")elifInt (id_add) ==440103: Print("Province City: Guangdong province Guangzhou Liwan District")elifInt (id_add) ==440104: Print("Province City: Yuexiu District, Guangzhou, Guangdong province")elifInt (id_add) ==440105: Print("Province City: Guangdong province Guangzhou Haizhu District") Birth=2017-int (Id_birth[0:4])Print("Age: {}". Format (birth))ifInt (id_sex)%2==0:Print('Gender: Female')Else: Print('Gender: Male')
----use string operations to generate URLs for each library of Python documents (start URL https://docs.python.org/3.6/library/index.html here)
3-E Practice String +,*,in,len (), eval ()
Python 9.13 Jobs