d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key + ':', d[key]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key + ':', d[key]
2019-01-24
d = {
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
d[72] = 'Paul'
print d
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
d[72] = 'Paul'
print d
2019-01-24
# -*- coding: utf-8 -*-
d = {
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
print 59 in d
d = {
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
print 59 in d
2019-01-24
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')
2019-01-24
for x in [1,2,3,4,5,6,7,8,9]:
for y in[0,1,2,3,4,5,6,7,8,9]:
if x < y:
print x*10 + y
for y in[0,1,2,3,4,5,6,7,8,9]:
if x < y:
print x*10 + y
2019-01-24
for x in [ '1','2','3','4','5','6','7','8' ]:
for y in [ '2','3','4','5','6','7','8','9' ]:
if x < y:
print x + y
for y in [ '2','3','4','5','6','7','8','9' ]:
if x < y:
print x + y
2019-01-24
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum = sum + x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum = sum + x
print sum
2019-01-24
sum = 0
x = 1
n = 1
while True:
sum = sum + x
x = x * 2
n = n + 1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum = sum + x
x = x * 2
n = n + 1
if n > 20:
break
print sum
2019-01-24
sum = 0
N = 100
x = 1
while x <= N:
sum = sum + x
x = x + 2
print sum
N = 100
x = 1
while x <= N:
sum = sum + x
x = x + 2
print sum
2019-01-24
L = [75, 92, 59, 68]
sum = 0.0
for name in L:
sum = sum + name
print sum / 4
sum = 0.0
for name in L:
sum = sum + name
print sum / 4
2019-01-24
score = 85
if score >= 90:
print 'excellent'
elif score >= 80:
print 'good'
elif score >= 60:
print 'passed'
else:
print 'failed'
if score >= 90:
print 'excellent'
elif score >= 80:
print 'good'
elif score >= 60:
print 'passed'
else:
print 'failed'
2019-01-24
score = 55
if score >= 60:
print 'passed'
else:
print 'failed'
print
if score >= 60:
print 'passed'
else:
print 'failed'
2019-01-24