sum = 0
x = 1
while x<=100 and x%2 != 0:
sum +=x
print sum
x = 1
while x<=100 and x%2 != 0:
sum +=x
print sum
2015-09-18
print 'hello, python'
print 'hello,', 'python'
print 'hello,', 'python'
2015-09-17
s = set(['Adam', 'Lisa', 'Bart', 'Paul','adam','bart'])
print 'adam' in s
print 'bart' in s
print 'adam' in s
print 'bart' in s
2015-09-17
print [int(x+y+x) for x in '123456789' for y in '0123456789']
2015-09-17
def average(*args):
return float(sum(args)) and float(sum(args)) / len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
return float(sum(args)) and float(sum(args)) / len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-09-17
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'adam:', d['Adam']
if 'Lisa' in d:
print 'lisa:',d['Lisa']
if d.get('Bart'):
print 'bart:',d['Bart']
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'adam:', d['Adam']
if 'Lisa' in d:
print 'lisa:',d['Lisa']
if d.get('Bart'):
print 'bart:',d['Bart']
2015-09-17