Hello world!
Print ("Hello Word")
Simple Interactive (interactive, file-style) textbook P19
The user enters two numbers and calculates and outputs the sum of two digits:
N1=input ("1") n2=input ("2:")Print (Float (N1) +float (n2))
The user enters the triangular three-side length and calculates the area of the triangle: (Helen Formula)
A = float (input ('input triangle First side length:')) b= Float (Input ('input Triangle Second side length:')) C= Float (Input ('input triangle Third side length:'))#Calculate half Perimeters = (A + B + c)/2Print('triangular half-perimeter is%0.2f'%s)#calculate area with Helen Formula S=√[p (P-A) (p-b) (p-c)]{a,b,c for edge length, p for half perimeter = (a+b+c)/2}Area = (s* (s-a) * (s-b) * (S-C)) * * 0.5Print('triangular area of%0.2f'%area)
Enter a radius to calculate the area of the circle.
pi=3.14= float (input ("))# calculates the area of the circle areas = pi*r*r Print(' Circle area of%0.2f' %area)
Draw a set of identical tangent circles
Import turtleturtle.circle (turtle.circle)turtle.circle($)turtle.circle (100 )
Draw a Pentagram
Import turtleturtle.hideturtle () turtle.speed()Turtle.begin_fill () for in range (5): turtle.forward ( turtle.left(144) Turtle.end_fill ( )
Draw an all-yellow pentagram
Import turtleturtle.hideturtle () turtle.speed()turtle.color ("green" ) ) Turtle.fillcolor ("green") Turtle.begin_fill ()for in Range (5): turtle.forward (+) turtle.left (144) Turtle.end_fill ()
Python input and output exercises, arithmetic exercises, turtle preliminary exercises