1, Python list sort reverse, sort, sorted operation method detailed
Reverse (reverse/reverse)
>>>
>>> x=[1,2,3,4]
>>> X.reverse ()
>>> Print X
[4, 3, 2, 1]
>>>
Sort (positive order/small to Large)
>>>
>>> y=[0,5,2,7]
>>> Y.sort ()
>>> Print Y
[0, 2, 5, 7]
>>>
Sorted (that is, you can keep the original list, and you can get a sorted list)
>>> z=[1,3,5,2,4]
>>> a=sorted (z)
>>> Print Z
[1, 3, 5, 2, 4]
>>> Print a
[1, 2, 3, 4, 5]
>>>
Enter the number by the small to the large sort
[email protected] ~]# cat a.py
#!/usr/bin/python#-*-coding:utf-8-*-number1=int (raw_input ("Please input your number:") Number2=int (Raw_input (" Please input your number: ") Number3=int (raw_input (" Please input your number: ")) Number=[number1,number2,number3] Number.sort () Print number
Results:
[email protected] ~]# python a.py
Please input your number:5please input your number:2please input your number:6[2, 5, 6]
2. Calculate the odd number within 1 to 100 and
Solution 1
#!/usr/bin/python#-*-coding:utf-8-*-i=1sum=0while (i<100): Sum=sum+ii=i+2print sum
Solution 2
#!/usr/bin/python#-*-coding:utf-8-*-i=1sum=0while (i<100): if (i% 2 ==1): Sum=sum+ii=i+2print sum
Results: 2500
Similarly-------------------
Calculates even numbers from 1 to 100 and
#!/usr/bin/pythona=0sum=0while (a<=100): Sum=sum+a a=a+2print sum
Results: 2550
3, 99 multiplication table
[email protected] ~]# cat a.py
#!/usr/bin/pythoni = 1while (i<=9): J=1 while (j<=i): Print J, "X", I, "=", j*i, "\ T", J+=1 print "" I+=1
Results:
[email protected] ~]# python a.py
1 x 1 = 1 1 x 2 = 2 2 x 2 = 4 1 x 3 = 3 2 x 3 = 6 3 x 3 = 9 1 x 4 = 4 2 x 4 = 8 3 x 4 = 12 4 x 4 = 16 1 x 5 = 5 2 x 5 = 10 3 x 5 = 15 4 x 5 = 20 5 x 5 = 25 1 x 6 = 6 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36 1 x 7 = 7 2 x 7 = 14 3 x 7 = 21 4 x 7 = 28 5 x 7 = 35 6 x 7 = 42 7 x 7 = 49 1 x 8 = 8 2 x 8 = 16 3 x 8 = 24 4 x 8 = 32 5 x 8 = 40 6 x 8 = 48 7 x 8 = 56 8 x 8 = 64 1 x 9 = 9 2 x 9 = 18 3 x 9 = 27 4 x 9 = 36 5 x 9 = 45 &nbSp;6 x 9 = 54 7 x 9 = 63 8 x 9 = 72 9 x 9 = 81
python--Small Problem Practice