Python基础练习01

时间:2021-09-08 18:37:15
# 1.字符串反转保留空格 例如:I Love China! => China! Love I
 
def fanzhuan(s1):
    arr =  s1.split(" ")
    num = 0
    for a in range(0,int(len(arr)/2)):
        ex = len(arr)-a-1
        num = arr[a]
        arr[a] = arr[ex]
        arr[ex] = num
 
    print(arr)
 
fanzhuan("I Love China! fuck the tommory asd !!")
 
# 2.打印100000以内的所有素数
 
a = 10000
arr = []
for i in range(2,10001):
    arr.append(i)
for i in range(0,10001):
    for j in range(2,i):
        if (i%j == 0 and i!=j):
                arr.remove(i)
                break
print(arr)