隨便寫寫。python挑戰一百題
阿新 • • 發佈:2018-11-01
網址:來源
1.
print(a+b)
2.
print(a[::-1])
3.
L.sort()
print(L)
4.
c=list(a.keys())
c.sort()
print(','.join(str(i)for i in c))
5.
c=""
for i in range(0,len(a),2):
c+=a[i]
print(c)
6.
vis = [1]*101 vis[0]=vis[1]=0 primes = list() ans = [] def getprime(): for i in range(2,101): if vis[i]: ans.append(str(i)) primes.append(i) for j in primes: if i*j>100: break vis[i*j]=0 if i%j==0: break print(" ".join(ans)) getprime() 尤拉法線性篩選法
7.
print(a*b,2*(a+b),sep=' ')
8.
L.sort()
if(len(L)-1)%2==0:
print(L[int(len(L)/2)])
else:
print(L[(len(L)-1)//2]+L[len(L)/2])/2.0
9.
def gcd(a,b):
return a if(b==0)else gcd(b,a%b)
print(gcd(n,m))
10.
def gcd(a,b):
return a if(b==0)else gcd(b,a%b)
print(a*b//gcd(a,b))
11.
sum=0 a=1 for i in range(len(L)): a*=L[i] while(a>=10): if(a==10): sum+=1 a=1 elif(a%10==0): sum+=1 a/=10 else: a=a%10 print(sum)
12.
a=1
for i in range(len(L)):
a*=L[i]
while(a>=10):
if(a==10):
a=1
elif(a%10==0):
a/=10
else:
a=a%10
ans = 0 if(a%2==0) else 1
print (ans)
13.
sum=0
while(a):
if(a&1):
sum+=1
a=a>>1
print(sum)
14.
import this as ruozhiti print(ruozhiti.s)
15.
print(a.lower())
16.
def gcd(a,b):
return a if(b==0)else gcd(b,a%b)
def gg(a,b):
cnt=0
for i in range(1,gcd(a,b)+1):
if(a%i==0 and b%i==0):
cnt+=1
return cnt
print(gg(a,b))
17.
import math
def gg(a,b):
d=a*b
i=int(math.sqrt(d))+1
for g in range(i,0,-1):
if(d%g==0):
c = g
m=int(d/g)
break
print(c,m)
gg(a,b)
18.
a="OurWorldIsFullOfLOeE"
a=a.upper()
c="LOVE"
d="SINGLE"
print(c)if (c in a) else print (d)
19.