Topic:
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:]))
Results:
3. Simple calculation
N1 = input (' Enter the first number:'= input (' Please enter a second number:' ) = Int (n1) +int (n2)print("sum=%d"% (sum))
Results:
Use one line of code:
Print (' two number of%.2f'% (float (input (' Enter first number:') ') +float (input ( ' Please enter a second number: ')))
Results:
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)
Results:
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 ')
Results:
6, draw a group of same cut round
Import turtleturtle.circle (turtle.circle)turtle.circle(())turtle.circle ( 200)
Results:
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)
Results:
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 ()
Results:
Python input and output exercises, arithmetic exercises, turtle preliminary exercises