Python Programming: Basic 1 Exercise __python

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.