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

Source: Internet
Author: User


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

1. Hello world!

Print ('Hello world! ' ) 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:]))


3. Simple calculation

N1 = input (' Enter the first number:'= input (' Please enter a second number:'  ) = Int (n1) +int (n2)print("sum=%d"% (sum))


Use one line of code:

Print (' two number of%.2f'% (float (input (' Enter first number:') ') +float (input ( ' Please enter a second number: ')))


4, calculate the area of the triangle

L1 = float (input (' Enter the length of the first edge:'= float (input (' Enter the length of the second edge: '  = float (input (' Enter the length of the third side:'= (L1+L2+L3)/2= (p* (P-L1) * (P-L2) * (P-L3)) **0.5print(' Triangle area:%.2f'%s)


5, calculate the area of the circle

R = Float (input (' Enter the radius of the circle:'= r**2*3.14print( The area of the circle is:%.2f  '%s ')


6, draw a group of same cut round

Import ( ( 200)


7. Draw a Pentagram

Import Turtleturtle.forward (turtle.right) (144) Turtle.forward(turtle.right) ( 144) Turtle.forward ($) turtle.right (144) Turtle.forward(+) turtle.right ( 144) Turtle.forward (200)


8. Draw a All-yellow pentagram

Import Turtleturtle.color ('yellow') turtle.fillcolor ('Yellow  ') Turtle.begin_fill (Turtle.forward)turtle.right(144) Turtle.forward (turtle.right) turtle.forward (144)turtle.right (144) Turtle.forward (turtle.right) (144) Turtle.forward() Turtle.end_fill () 


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: 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.