- Hello world!
Print ("Hello world!! ")
- Simple Interactive (interactive, file-style) textbook P19
Name=input ("What is your name?\n") where=input ("where is you now?\n") Age=input ("How is old is you ? \ n")Print("your name is {}". Format (name))Print("You live in {}". Format (where)Print("You is {} years old". Format (age))
- The user enters two numbers and calculates and outputs the sum of two digits:
Num1=input ("input a number:\n") num2=input ("input an other number:\ n")print(sum,end=" ") sum=num1+num2
- The user enters the triangular three-side length and calculates the area of the triangle: (Helen Formula)
-
a = float (input ( " Enter first edge length: " )) b = float (Input ( " Enter the second side edge length: " = float (input ( " Enter the third edge length: " )) s = (A + B + c)/2area = (s* (s-a) * (s-b) * (S-C) * * * 0.5print ( " "%area)
- Enter a radius to calculate the area of the circle.
pi=3.1415926R=float (input (" Please enter radius:"))area =pi*r*RPrint (" area of%0.2f"%area)
- Draw a set of identical tangent circles
Import turtleturtle.speed (turtle.circle)turtle.circle(()turtle.circle ( ) turtle.circle (40)
- draw a pentagram
import Turtleturtle.speed ( 100) Turtle.forward ( 100 144) Turtle.forward ( 100 144) Turtle.forward ( 100 144) Turtle.forward ( 100 144) Turtle.forward ( 100 144)
- Draw an all-yellow pentagram
Import turtleturtle.speed (turtle.fillcolor) ("yellow") Turtle.begin _fill (Turtle.forward)turtle.right(144) Turtle.forward (+) turtle.right(144 ) Turtle.forward (turtle.right) (144) Turtle.forward(+)turtle.right ( 144) Turtle.forward (+) turtle.right (144) Turtle.end_fill ()
Thinking:
- Draw a set of concentric circles.
ImportTurtle#Draw First CircleTurtle.penup () turtle.goto (0,-200) Turtle.pendown () turtle.circle (200)#Draw Second CircleTurtle.penup () turtle.goto (0,-150) Turtle.pendown () turtle.circle (150)#Draw Third CircleTurtle.penup () turtle.goto (0,-100) Turtle.pendown () turtle.circle (100)#Draw Fourth CircleTurtle.penup () turtle.goto (0,-50) Turtle.pendown () turtle.circle (50)
- Draw five pentagram on the national flag
Python input and output exercises, arithmetic exercises, turtle preliminary exercises