Python input and output exercises, arithmetic exercises, turtle preliminary exercises

Source: Internet
Author: User
Tags goto

1.Hello world!

1 print(‘Hello World!‘)

Simple interaction (Interactive, file-style)

1 name=input (' Please put your name: ') 2 print (' Hi {} '. Format (name)) 3 print (' Mr. {} hobbit is eating, sleeping, hitting peas '. Format (Name[0])) 4 Print (' Dear {} should go to work! '. Format (name[1]))

3. The user enters two numbers and calculates and outputs the sum of two digits:

Print (' Sub is:{} '. Format (float (input (' first number: ')) +float (input (' second number: ')))

4. User input triangle three-side length, and calculate the area of the triangle: (Helen Formula)

1 a=input (' Please enter first edge: ') 2 b=input (' Please enter second edge: ') 3 c=input ("Please enter third side:") 4 c= (float (a) +float (b) +float (c)) 5 s= (c/2* (float (C/2) -float (a)) * (Float (C/2)-float (b)) * (Float (C/2)-float (C))) **0.56 print (' The area of the triangle is {} '. Format (S))

5. Enter a radius to calculate the area of the circle.

R=input (' Please input r: ') Area=3.1415*float (R) *float (r) print ("{:. 2f}". Format (area))

6. Draw a set of identical tangent circles

1 Import turtle2 turtle.pensize (Ten) 3 turtle.circle (4) turtle.circle (+) 5 turtle.circle (+) 6 turtle.circle (120)

7. Draw a Pentagram

1 Import turtle as T 2 t.speed (1) 3 for I in range (5): 4     T.forward (+) 5     t.right (144)

8. Draw a All-yellow pentagram

1 Import Turtle 2 turtle.color (' Yellow ') 3 turtle.fillcolor (' Yellow ') 4 turtle.speed (1) 5 turtle.pensize (Ten) 6 Turtle.begi N_fill () 7 for I in range (5): 8     Turtle.forward () 9     turtle.right (144) Turtle.end_fill ()

Additional question 1: Draw a set of concentric circles:

1 Import Turtle 2 Turtle.penup () 3 Turtle.goto (0,-100) 4 Turtle.pendown () 5 turtle.circle (+) 6 turtle.penup () 7 turtle.g Oto (0,-80) 8 Turtle.pendown () 9 turtle.circle ($) turtle.penup () Turtle.goto (0,-60) Turtle.pendown () 13 Turtle.circle () Turtle.penup () Turtle.goto (0,-40) Turtle.pendown () turtle.circle (40)

Draw five pentagram on the national flag

Import Turtle
Def draw_square ():
Turtle.color (' Red ')
Turtle.fillcolor (' Red ')
# turtle.speed (1)
Turtle.penup ()
Turtle.goto (-200,200)
Turtle.pendown ()
Turtle.begin_fill ()
Turtle.forward (400)
Turtle.right (90)
Turtle.forward (200)
Turtle.right (90)
Turtle.forward (400)
Turtle.right (90)
Turtle.forward (200)
Turtle.right (90)
Turtle.end_fill ()
# Time.sleep (5)
Def Draw_big_star ():
Turtle.color (' Yellow ')
Turtle.fillcolor (' Yellow ')
# turtle.speed (1)
Turtle.penup ()
Turtle.goto (-175,155)
Turtle.pendown ()
Turtle.begin_fill ()
For I in range (5):
Turtle.forward (50)
Turtle.right (144)
Turtle.end_fill ()
def draw_smallstar (x, Y, z):
Turtle.color (' Yellow ')
Turtle.fillcolor (' Yellow ')
# turtle.speed (1)
Turtle.penup ()
Turtle.goto (x, y)
Turtle.pendown ()
Turtle.begin_fill ()
Turtle.right (z)
For I in range (5):
Turtle.forward (15)
Turtle.right (144)
Turtle.end_fill ()
Draw_square ()
Draw_big_star ()
Draw_smallstar ( -110,175,5)
Draw_smallstar ( -90,155,15)
Draw_smallstar ( -95,125,25)
Draw_smallstar ( -110,105,0)

Python input and output exercises, arithmetic exercises, turtle preliminary exercises

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.