1. Hello world!
Print("Hello world! ")
2. Simple Interactive (interactive, file-style) textbook P19
>>> name = input ("pleaseinput your name:")>>> please input Your name:poonprint(name)>>> Poon
3, the user input two numbers, calculate and output two numbers of the sum:
S1 = float (Input ("Please input the first num:")) S2= Float (Input ("Please input the second num:")) Sum= S1 +S2Print("The result is:%s"%sum)Print("The result is%.2f"% ((Float (input ("The first num is")) + (float (input ("The secibd num is")))))
4, the user input triangle three-side length, and calculate the area of the triangle: (Helen Formula)
A = float (input ( " please input the A side: " )) b = float (input ( " please input the B side: " = float (input ( " please input the C side: " )) p = (A + B + c)/2s = (p * (p-a) * (p-b) * (P-C)) * * 0.5print ( " the Square is:%.2f "% s)
5. Enter the radius to calculate the area of the circle.
Fromimport= float (input ("pleaseinput the R:"= pi * (r**2 )print("Thearea is%.2f" % s)
6, draw a group of same cut round
Import turtle as Tt.speed (1) t.circle (ten) t.circle (t.circle)(30 )
7, draw a pentagram
import turtle as Tt.speed ( 1) for I in range (5)
T.right ( 144)
8. Draw a All-yellow pentagram
Import turtle as Tt.fillcolor ("red") T.begin_fill ()while True: t.forward ( t.right) (144) if abs (POS ()) <1 : Break T.end_fill ()
Python input and output exercises, arithmetic exercises, turtle preliminary exercises