Give you both Var A and B, print the value of a+b, just do it!!
Answer:
print a+b
Give you a list L, such as l=[2,8,3,50], sort L in ascending order and output,
The result of example L is [2,3,8,50]
Answer:
L=[2,8,3,50]
L.sort() or L.sorted()
print L
- Give you a string a, such as a= ' 12345 ', to reverse the output a.
Answer:a = ‘12345’b = a[::-1]print b
- Give you a dictionary a, such as A={1:1,2:2,3:3}, output the key of dictionary A to ', ' link, such as ' a '.
Answer:print(‘,‘.join(map(str, a.keys())))
Map Function Example
>>> def add100(x):... return x+100... >>> List = [11,22,33]>>> map(add100, List)[111122133]
- Give you a string a, the output word Fu Chi number position of the string. such as A= ' 12345 ', then output 135.
Answer:print a[::2]
- All prime numbers within the output 100, separated by a space between primes
answer:primes =[] for i in range ( 2 , 100 ): flag = False For j in range (2 , int (i /2 ) +1 ): if i % j = = 0: flag =trueif not Flag:primes. Append (i ) print (. Join (Map (str, primes ))
- Known rectangle length A, width b, output its area and perimeter, area and perimeter separated by a space
str(a*b)+‘ ‘+str(2*(a+b))
- Give you a list L, such as l=[0,1,2,3,4], the median of the output l (if the result is a decimal, one decimal place is reserved).
Answer:L = sorted(L)iflen(L)%2 == 1: x = L[(len(L)-1)/2]else: x = L[len(L)/2-1]/2.0+L[len(L)/2]/2.0print x
- Give you two positive integers a and B, and output their greatest common divisor.
Answer:printmaxforin range(1if (a%i+b%i)==0])
- Give you two positive integers a and B, and output their least common multiple.
a*b/maxforin range(1,aif (a%i+b%i)==0])
Not finished, to be continued
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MAC Learning Series Python Challenge 1-10