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]
2019-07-27
python2版本:
L = range(1, 101)
print L[:10]
print L[2::3]
print L[4:50:5]
python3版本:在python3中range的实现变了,并不是返回一个list类型,而是返回一迭代对象。
L= list(range(1, 101))
print(L[:10])
print(L[2::3])
print(L[4:50:5])
L = range(1, 101)
print L[:10]
print L[2::3]
print L[4:50:5]
python3版本:在python3中range的实现变了,并不是返回一个list类型,而是返回一迭代对象。
L= list(range(1, 101))
print(L[:10])
print(L[2::3])
print(L[4:50:5])
2019-07-27
sum = 1
x = 1
while True:
x+=1
if x > 100:
break
if x%2==0:
continue
sum+=x
print sum
x = 1
while True:
x+=1
if x > 100:
break
if x%2==0:
continue
sum+=x
print sum
2019-07-27
sum = 0
x = 1
n = 0
while True:
sum+=2**n
n+=1
if n>=20:
break
print sum
x = 1
n = 0
while True:
sum+=2**n
n+=1
if n>=20:
break
print sum
2019-07-27
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59,
}
for key in d:
print key + ': '+ str(d.get(key))
'Adam': 95,
'Lisa': 85,
'Bart': 59,
}
for key in d:
print key + ': '+ str(d.get(key))
2019-07-27
本题调用有误导,输入average()时返回结果是0.0而不是0.
def average(*args):
if args==():
return 0.0
else:
return sum(args*1.0)/len(args)
print (average())
print (average(1, 2))
print (average(1, 2, 2, 3, 4))
def average(*args):
if args==():
return 0.0
else:
return sum(args*1.0)/len(args)
print (average())
print (average(1, 2))
print (average(1, 2, 2, 3, 4))
2019-07-27
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for p in d:
print p,':',d[p]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for p in d:
print p,':',d[p]
2019-07-27
## xy
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 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
2019-07-27
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2!=0:
sum = sum+x
continue
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2!=0:
sum = sum+x
continue
print sum
2019-07-27
sum = 0
x = 1
n = 0
while True:
a = 2**n
sum = sum + a
n=n+1
if n==20:
break
print sum
x = 1
n = 0
while True:
a = 2**n
sum = sum + a
n=n+1
if n==20:
break
print sum
2019-07-27
#input code
print('hello, python.')
print 'hello,','python.'
print('hello, python.')
print 'hello,','python.'
2019-07-27
#Enter a code
print(100<99)
print(0xff==255)
print(123456)
print('learn python in imooc')
print(100<99)
print(0xff==255)
print(123456)
print('learn python in imooc')
2019-07-27
def greet(x='world'):
print('Hello,'+x+'.')
greet()
greet('Bart')
print('Hello,'+x+'.')
greet()
greet('Bart')
2019-07-26