1. Input two points on the plane, calculate the distance of two points
Import Math
X1,y1=input (' Please, the start point x1,y1: ')
X2,y2=input (' Please, the start point x2,y2: ')
Distance=math.sqrt ((x1-x2) **2+ (y1-y2) **2)
print ' distance= ', distance
Please, the start point x1,y1:0,0
Please, the start point x2,y2:3,4
Distance= 5.0
2. Enter any 3 words and arrange them in dictionary order
String=raw_input (' Please input 3words with "," in them: ')
X,y,z=string.split (', ')
If X>y:
X,y=y,x
If X>z:
X,z=z,x
If Y>z:
Y,z=z,y
Print X,y,z
Please input 3words with "," in Them:iker,peng,xiao
Iker Peng Xiao
3. Solution Two Yuan one time equation group. Enter their coefficients and output the results. (We use the NumPy library)
Import NumPy as NP
A=np.zeros ((2,3))
A[0][0],a[0][1],a[0][2]=input (' Please input 3 numbers for the ' "
A[1][0],a[1][1],a[1][2]=input (' Please input 3 numbers for the second function: ')
If a[0][0]*a[1][1]==0:
Print "Are you kidding me?"
Else
a[1]=a[0]* (-a[1][0]/a[0][0]) +a[1]
a[0]=a[1]* (-a[0][1]/a[1][1]) +a[0]
print ' The answer is:x1= ', a[0][2]/a[0][0], ' x2= ', a[1][2]/a[1][1]
Please input 3 numbers for the function:1,2,3
Please input 3 numbers for the second function:4,9,7
The answer is:x1= 13.0 x2=-5.0
Please input 3 numbers for the function:0,1,2
Please input 3 numbers for the second function:1,2,3
Are you kidding me?
4, the matrix is output by its shape
A=input (' Please input a 3*3 array: ')
For X in a:
S= '
For y in x:
s1= '%6d '%y
S=s+s1
Print S
Please input a 3*3 array:[[1,2,1],[2,3,4],[4,5,0]]
1 2 1
2 3 4
4 5 0