a=8
b=15
x=a ** 2 - 4 * b
print x>=0 and x**0.5==int(x**0.5) and "YES" or "NO"
- read more
38.Simple list of conversion
read moreL=['abc','d','efg'] print "".join([x for x in L])
37.pythagorean theorem
read morea=3 b=4 print "%.3f" % (a**2+b**2)**0.5
36.Maximum not continuous subsequence
read moreL = [2, -3, 3, 50] for i in range(2,len(L)): L[i]=(max(max(L[0:i-1]),0)+L[i]) print max(L)
35.Maximum continuous subsequence
read moremaxim=0 sum=0 for i in range(len(L)): if L[i]<0: maxim=max(sum,maxim) sum=0 else: sum+=L[i] print max(sum,maxim) # don't forget the last one
34.The password generated
read morea = 1 b = 77 x = 1 y = 14 lister, ans, a = [], [], a%b*10 while a not in lister: lister.append(a) # 1. not includes x of x.123456 ans.append(a // b) a = (a % b)*10 nolooplen = lister.index(a) # when the iteration appears in ans looplen = len(ans ...
33.Big power operation
read morea=9 n=50 def pow_mod(a,n,mod): # a**50=(a**2)**25, a**25=(a**2)**12*a, res = 1 while n > 0 : if n % 2 == 1: # if n is odd, extract new_a%mod and multiply res res = res * a % mod a = a * a % mod # 1.a=new_a ...
32.Triangle shape
read morea=3 b=4 c=5 [a,b,c]=sorted([a,b,c]) print a+b<c and 'W' or a*a + b*b < c*c and 'D' or a*a + b*b == c*c and 'Z'or 'R'
31.The number of peaks
read moreh=[0.9,1.2,1.22,1.1,1.6,0.99] print sum([1 for i in range(1,len(h)-1) if h[i]>h[i-1] and h[i]>h[i+1]])
29.Judgment of the triangle
read morea=5,b=7,c=10 print sorted([a,b,c])[0] + sorted([a,b,c])[1] > sorted([a,b,c])[2] and 'YES' or 'NO'