Python
Python
Python for
for iterating_var in sequence:
for iterating_var in sequence:
statements(s)
statements(s)
Python while
while expression:
while expression:
statement(s)
statement(s)
whilefor forwhile
2~100
#!/usr/bin/python
# -*- coding: UTF-8 -*-
i = 2
while(i < 100):
j = 2
while(j <= (i/j)):
if not(i%j): break
j = j + 1
if (j > i/j) : print i, " "
i = i + 1
print "Good bye!"
:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 Good bye!
302***[email protected]
100
#!/usr/bin/python # -*- coding: UTF-8 -*- num=[]; i=2 for i in range(2,100): j=2 for j in range(2,i): if(i%j==0): break else: num.append(i) print(num)302***[email protected]
zero
562***[email protected]
#!/usr/bin/python # -*- coding: UTF-8 -*- #* i=1 #j=1 while i<=9: if i<=5: print ("*"*i) elif i<=9 : j=i-2*(i-5) print("*"*j) i+=1 else : print("")zero
562***[email protected]
(+__+)
lk0***[email protected]
#!/usr/bin/python # -*- coding: UTF-8 -*- array = [9,2,7,4,5,6,3,8,1,10] L = len(array) for i in range(L): for j in range(L-i): if array[L-j-1]<array[L-j-2]: array[L-j-1],array[L-j-2]=array[L-j-2],array[L-j-1] for i in range(L): print array[i],(+__+)
lk0***[email protected]
C6H8O7
235***[email protected]
#!/usr/bin/python # -*- coding: UTF-8 -*- #[a,b] a = 1000 # b = 10000 # E = [] for num in range(a,b+1): snum = int(num*0.5+1) for i in range(2,snum): if num%i == 0: break else: E.append(num) print a,'',b,'',E print a,'',b,'',len(E),''C6H8O7
235***[email protected]
boweiqingfeng
yyx***[email protected]
:
array = [8,2,6,3,4,5,7,1,10,9] L=len(array) for i in range(1,L): temp = array[i] array.remove(array[i]) for j in range(i): if array[j]>temp: array.insert(j,temp) break else: array.insert(i,temp) print(array)boweiqingfeng
yyx***[email protected]