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

Source: Internet
Author: User

Topic:

1. Hello world!
2. Simple Interactive (interactive, file-style) textbook P19
3. The user enters two numbers, calculates and outputs the sum of two digits (try to implement it in one line of code).
4. The user enters the triangular three-side length and calculates the area of the triangle: (Helen Formula)
5. Enter a radius to calculate the area of the circle.
6. Draw a set of identical tangent circles
7. Draw a Pentagram
8. Draw an all-yellow pentagram

1: Output Hello world!

`Print ('helloworld') Hello World`

2: Simple interaction

`Name = input (" Enter name:")print("{} Students, learn python, promising!")  . Format (name)print("{} heroes, learn Python, promising!")  . Format (name[0))print("{} brother, learn Python, promising!")  ". Format (name[1:]))`

Effect:

Interactive:

` while a <:    Print(A, end=',')    = B, A + B0,1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987,`

`>>> NUM1 = input (' Please enter first number:') Enter the first number:11>>> num2 = input ('  Please enter a second number:') Enter the second number:12>>> sum = Int (NUM1) +int (num2)Print ("sum=%d"%(sum)) sum`

One line of code implementation:

`Print (' two and%.2f'% (float (input (' Enter first number:') ') +float (input ('  Please enter the second number:'))) Enter the first number: Please enter the second number:two sum of each .`

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

`A = float (input (' enter ' The first edge of the triangle:'= float (input (' Please enter the second side of the triangle length:  '= float (input (' Enter ' triangle third side length:'= (a+b+c)/2= (p* (p-a * (p-b) * (P-C)) * * * 0.5print(' triangular area bit%0.2f' %area)`

Results:

5: Enter the radius to calculate the area of the circle

`Import= float (input (' Enter radius of circle:'= math.pi* (r**2)  Print(' round area%0.2f'%area)`

Effect:

6: Draw a same tangent circle

`Import Turtle>>> turtle.circle (+)>>> turtle.circle (+)>>> Turtle.circle (+)`

Effect:

7 Draw a Pentagram

`Import Turtle>>> turtle.forward (+)>>> turtle.right (144)>>> Turtle.forward >>> turtle.right(144)>>> turtle.forward (+)> >> turtle.right (144)>>> turtle.forward (+)>>> turtle.right (144) >>> Turtle.forward (+)`

Effect:

8: Draw a color-filled pentagram

`>>>ImportTurtle>>> Turtle.fillcolor ("Yellow")>>> Turtle.pencolor ("Yellow")>>>Turtle.begin_fill ()>>> Turtle.forward (100)>>> Turtle.right (144)>>> Turtle.forward (100)>>> Turtle.right (144)>>> Turtle.forward (100)>>> Turtle.right (144)>>> Turtle.forward (100)>>> Turtle.right (144)>>> Turtle.forward (100)>>>Turtle.end_fill ()>>>`

Effect:

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

Related Keywords:
Related Article

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.