L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L,start=1):
print index, '-', name
for index, name in enumerate(L,start=1):
print index, '-', name
def average(*args):
s = 0
i = 0
for arg in args:
i=i+1.0
s += arg
return s/i
print average(0)
print average(1, 2)
print average(1, 2, 2, 3, 4)
s = 0
i = 0
for arg in args:
i=i+1.0
s += arg
return s/i
print average(0)
print average(1, 2)
print average(1, 2, 2, 3, 4)
2019-01-14
def greet(s='world.'):
print 'Hello,',s
greet()
greet('Bart.')
print 'Hello,',s
greet()
greet('Bart.')
2019-01-14
import math
def quadratic_equation(a, b, c):
return (-b+math.sqrt(b*b-4*a*c))/(2*a),(-b-math.sqrt(b*b-4*a*c))/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
return (-b+math.sqrt(b*b-4*a*c))/(2*a),(-b-math.sqrt(b*b-4*a*c))/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2019-01-14
def square_of_sum(L):
s = 0;
for v in L:
s = s+pow(v,2)
return s
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
s = 0;
for v in L:
s = s+pow(v,2)
return s
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2019-01-14
import math
def quadratic_equation(a, b, c):
if (b*b-(4*a*c))>=0:
x1 = (-b+math.sqrt(b*b-(4*a*c)))/(2*a)
x2 = (-b-math.sqrt(b*b-(4*a*c)))/(2*a)
return x1, x2
else:
return
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
# math.sqrt
def quadratic_equation(a, b, c):
if (b*b-(4*a*c))>=0:
x1 = (-b+math.sqrt(b*b-(4*a*c)))/(2*a)
x2 = (-b-math.sqrt(b*b-(4*a*c)))/(2*a)
return x1, x2
else:
return
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
# math.sqrt
2019-01-14
L = []
i = 0
j = 0;
while j<100:
i= i+1
j= j+1
L.append(i*j)
print sum(L)
i = 0
j = 0;
while j<100:
i= i+1
j= j+1
L.append(i*j)
print sum(L)
2019-01-14
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for v in L:
if v in s:
s.remove(v)
else:
s.add(v)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for v in L:
if v in s:
s.remove(v)
else:
s.add(v)
print s
2019-01-14