def square_of_sum(L):
sum = 0
for x in L:
sum = sum + x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum = 0
for x in L:
sum = sum + x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2018-11-20
L = []
x=1
while x<=100:
y = x*x
L.append(y)
x = x+1
print sum(L)
x=1
while x<=100:
y = x*x
L.append(y)
x = x+1
print sum(L)
2018-11-20
months = set(['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'])
x1 = 'Feb'
x2 = 'Sun'
if x1 in months:
print 'x1: ok'
else:
print 'x1: error'
if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
x1 = 'Feb'
x2 = 'Sun'
if x1 in months:
print 'x1: ok'
else:
print 'x1: error'
if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
2018-11-20
sum = 0
x = 2
y = 0
while True:
if y == 20:
break
sum = sum + x**y
y = y + 1
print(sum)
x = 2
y = 0
while True:
if y == 20:
break
sum = sum + x**y
y = y + 1
print(sum)
2018-11-19
def split(a):
if len(a)!=0:
x=a[:1]
return x.upper()+a[1:].lower()
return None
print split('hello')
print split('sunDAY')
print split('september')
print split('')
if len(a)!=0:
x=a[:1]
return x.upper()+a[1:].lower()
return None
print split('hello')
print split('sunDAY')
print split('september')
print split('')
2018-11-19
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
else:
if x%2==0:
continue
sum = sum + x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
else:
if x%2==0:
continue
sum = sum + x
print sum
2018-11-19
def l(n, a, b, c):
print 'l(', n, a, b, c,')'
if n ==1:
print a, '-->', c
return
l(n-1, a, c, b)
print a, '-->', c
l(n-1, b, a, c)
l(3, 'A', 'B', 'C')
print 'l(', n, a, b, c,')'
if n ==1:
print a, '-->', c
return
l(n-1, a, c, b)
print a, '-->', c
l(n-1, b, a, c)
l(3, 'A', 'B', 'C')
2018-11-18