Python Learning-Textbook Program Practice (week more)

Source: Internet
Author: User

1. Draw a square helix

ImportTurtleturtle.setup (600,300,200,200) Turtle.pensize (1) Turtle.color ('Green') I=0 whilei<160: Turtle.seth (90) TURTLE.FD (i+1) Turtle.seth (180) TURTLE.FD (i+2) Turtle.seth (-90) TURTLE.FD (i+3) turtle.seth (0) turtle.fd (i+4) I=i+4Turtle.seth (90) TURTLE.FD (161) Turtle.seth (180) TURTLE.FD (162) Turtle.seth (-90) TURTLE.FD (163)
View Code

2. Draw an angle-free square

ImportTurtledefdrawtriangle (angle): Turtle.seth (angle) Turtle.penup () turtle.fd (20) Turtle.down () turtle.fd (80) Turtle.penup () turtle.fd (20) Turtle.down () Turtle.setup (800,350) Turtle.pensize (1) Turtle.pencolor ("Black") forIinch(0,90,180): Drawtriangle (i) Turtle.seth (-90) Turtle.penup () turtle.fd (20) Turtle.down () turtle.fd (90H
View Code

3. Work five days a week, rest 2 days, rest day level down 0.01, working days to what extent, a year after the level and every effort 1% achieved the same effect.

#the idea of function programming#DaydayupImportMathdefDayup (DF): Dayup=1.0 forIinchRange (365):        ifI%7inch[6, 0]: Dayup=dayup* (1-0.01)        Else: Dayup=dayup* (1 +DF)returnDayupdayfactor=0.01 while(Dayup (Dayfactor) <37.78): Dayfactor+=0.001Print("dayfactoris:{:.3f}.". Format (Dayfactor))
View Code

4. Draw the progress bar

1. Multi-line accumulation does not refresh (time.sleep delay output)

#textprogress BarImport TimePrint("-----Execution Start-----") Scale=10 forIinchRange (scale+1): C= (I/scale) *100A, b="**"(In".."* (scale-i)Print("%{:^3.0f}[{}>-{}]". Format (c,a,b)) Time.sleep (0.1)Print("-----Execution Start-----")
View Code

2. Single-row refresh print function add parameter end= ' do not wrap the head with escape character ' \ R ' to move the output pointer to the beginning of the line note: The Idle mask line refresh function needs to run. PY Program

#textprogress BarImport TimePrint("-----Execution Start-----") Scale=10 forIinchRange (scale+1): C= (I/scale) *100A, b="**"(In".."* (scale-i)Print("\r%{:^3.0f}[{}>-{}]". Format (c,a,b), end="') Time.sleep (0.1)Print("-----End of execution-----")                            
View Code

3. Above based on increased running time monitoring Time.clock () function First call timing start, second and subsequent calls return with time difference from first time

#textprogress BarImport TimePrint("-----Execution Start-----") Scale=10T=Time.clock () forIinchRange (scale+1): C= (I/scale) *100T-=Time.clock () A, B="**"*i,".."* (scale-i)Print("\r%{:^3.0f}[{}>-{}]{:.2f}s". Format (c,a,b,-t), end="') Time.sleep (1)Print("-----End of execution-----")
View Code

Python Learning-Textbook Program Practice (week more)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.