x1 = 1
d = 3
n = 100
x100 = x1+3*(n-1)
s = (x1+x100)*n/2
print s
d = 3
n = 100
x100 = x1+3*(n-1)
s = (x1+x100)*n/2
print s
2016-01-22
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:',d.get('Adam')
print 'Lisa:',d.get('Lisa')
print 'Bart:',d.get('Bart')
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:',d.get('Adam')
print 'Lisa:',d.get('Lisa')
print 'Bart:',d.get('Bart')
2016-01-22
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print '%s:%s' %(k,v)
print 'average', ':', sum/len(d.values())
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print '%s:%s' %(k,v)
print 'average', ':', sum/len(d.values())
2016-01-22
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for i in d.itervalues():
sum+=i
print sum/len(d.values())
sum = 0.0
for i in d.itervalues():
sum+=i
print sum/len(d.values())
2016-01-22
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
2016-01-22
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print x[0],':',x[1]
for x in s:
print x[0],':',x[1]
2016-01-22
s = set(['Adam', 'Lisa', 'Bart', 'Paul'])
ss = set()
for a in s:
a = a.lower()
ss.add(a)
print 'adam' in ss
print 'bart' in ss
ss = set()
for a in s:
a = a.lower()
ss.add(a)
print 'adam' in ss
print 'bart' in ss
2016-01-22
for x in range(1,10):
for y in range(1,10):
if x >= y:
continue
print x*10 + y
for y in range(1,10):
if x >= y:
continue
print x*10 + y
2016-01-22
sum = 0
x = 0
while True:
x = x + 1
if x%2 == 0:
continue
if x > 100:
break
sum = sum + x
print sum
x = 0
while True:
x = x + 1
if x%2 == 0:
continue
if x > 100:
break
sum = sum + x
print sum
2016-01-22
sum = 0
x = 1
n = 1
while True:
sum = sum + x
x = 2 * x
n = n + 1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum = sum + x
x = 2 * x
n = n + 1
if n > 20:
break
print sum
2016-01-22
import math
def quadratic_equation(a, b, c):
data = b*b-4*a*c
if a == 0:
return -c/b
elif data == 0:
return -b/(2*a)
elif data < 0:
return none
else:
return (-b+math.sqrt(data))/(2*a),(-b-math.sqrt(data))/(2*a)
print quadratic_equation(2, 3, 0)
def quadratic_equation(a, b, c):
data = b*b-4*a*c
if a == 0:
return -c/b
elif data == 0:
return -b/(2*a)
elif data < 0:
return none
else:
return (-b+math.sqrt(data))/(2*a),(-b-math.sqrt(data))/(2*a)
print quadratic_equation(2, 3, 0)
2016-01-22
sum = 0
x = 1
while x < 100:
sum = sum + x
x = x + 2
print (sum)
x = 1
while x < 100:
sum = sum + x
x = x + 2
print (sum)
2016-01-22