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]
2016-01-10
如果不换行,,需要加一堆分号进去
x1 = 1; d = 3; n = 100; x100 = x1 + (n-1)*d; s = (x1+x100)*n/2; print (s)
x1 = 1; d = 3; n = 100; x100 = x1 + (n-1)*d; s = (x1+x100)*n/2; print (s)
2016-01-10
思考的代码:
age = 20
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
age = 20
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
2016-01-10
L = ['Adam', 95.5,'Lisa', 85, 'Bart', 59]
print L
运行结果['Adam', 95.5, 'Lisa', 85, 'Bart', 59]
L = ['Lisa', 85,'Adam', 95.5, 'Bart', 59]
print L
运行结果是['Lisa', 85, 'Adam', 95.5, 'Bart', 59]
所以如果不按次序,python依然可以打印出list,但我思考的是,应该会有一个函数可以进行自动按照要求进行排序打印的吧?不然数据一多,不可能人工排列好再输入进行打印。
期待后面的课程。
print L
运行结果['Adam', 95.5, 'Lisa', 85, 'Bart', 59]
L = ['Lisa', 85,'Adam', 95.5, 'Bart', 59]
print L
运行结果是['Lisa', 85, 'Adam', 95.5, 'Bart', 59]
所以如果不按次序,python依然可以打印出list,但我思考的是,应该会有一个函数可以进行自动按照要求进行排序打印的吧?不然数据一多,不可能人工排列好再输入进行打印。
期待后面的课程。
2016-01-10
for x in range(1,10):
for y in range(1,10):
if x<y:
print 10*x+y
for y in range(1,10):
if x<y:
print 10*x+y
2016-01-09
sum = 0
x = 0
while True:
x = x + 1
if x%2==0:
continue
if x > 100:
break
sum+=x
print sum
x = 0
while True:
x = x + 1
if x%2==0:
continue
if x > 100:
break
sum+=x
print sum
2016-01-09
sum = 0
x = 1
n = 1
while True:
sum+=x
x=x*2
if n>=20:
break
n+=1
print sum
x = 1
n = 1
while True:
sum+=x
x=x*2
if n>=20:
break
n+=1
print sum
2016-01-09
L = [75, 92, 59, 68]
sum = 0.0
for i in L:
sum+=i
print sum / 4
sum = 0.0
for i in L:
sum+=i
print sum / 4
2016-01-09