def average(*args):
num = len(args)
sum = 0.0
if num==0:
return sum
else:
for item in args:
sum += item
return sum/num
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
num = len(args)
sum = 0.0
if num==0:
return sum
else:
for item in args:
sum += item
return sum/num
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2018-08-03
def greet(name='world'):
print 'Hello,',name,'.'
greet()
greet('Bart')
print 'Hello,',name,'.'
greet()
greet('Bart')
2018-08-03
# -*- coding: UTF-8 -*-
def move(n, a, b, c):
if n==1:
print a,'-->',c
else:
move(n-1,a,c,b)#把a盘前面n-1个盘子借助c实现a盘移到b盘
print a,'-->',c#把a盘最后一个盘子放到c
move(n-1,b,a,c)#把b盘的n-1个盘子借助a盘移到c盘
move(4, 'A', 'B', 'C')
def move(n, a, b, c):
if n==1:
print a,'-->',c
else:
move(n-1,a,c,b)#把a盘前面n-1个盘子借助c实现a盘移到b盘
print a,'-->',c#把a盘最后一个盘子放到c
move(n-1,b,a,c)#把b盘的n-1个盘子借助a盘移到c盘
move(4, 'A', 'B', 'C')
2018-08-03
a = 'python'
print 'hello,', a or 'world' # or中python已经为true了,所以就直接返回了python
b = ''
print 'hello,', b or 'world' #or中‘ ’为false,所以取决与world,返回它
print 'hello,', a or 'world' # or中python已经为true了,所以就直接返回了python
b = ''
print 'hello,', b or 'world' #or中‘ ’为false,所以取决与world,返回它
2018-08-03
L = []
x=0
while True:
x=x+1
if x>100:
break
L.append(x*x)
print sum(L)
x=0
while True:
x=x+1
if x>100:
break
L.append(x*x)
print sum(L)
2018-08-02
months = set(['January','February','March','April','May','June','July','August','November','September','October','December'])
weeks = set(['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'])
别谢我,复习一下英文单词
weeks = set(['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'])
别谢我,复习一下英文单词
2018-08-02
sum = 0
x = 0
while True:
x += 1
if x > 99:
break
if x % 2 == 0:
continue
sum += x
print sum
x = 0
while True:
x += 1
if x > 99:
break
if x % 2 == 0:
continue
sum += x
print sum
2018-08-02
# -*- coding: utf-8 -*-
d = {
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
score = int(input("enter score: "))
for key,value in d.items():
if key == score:
print(str(key) + ": " + value)
d = {
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
score = int(input("enter score: "))
for key,value in d.items():
if key == score:
print(str(key) + ": " + value)
2018-08-02
from collections import OrderedDict
d = OrderedDict()
d['Adam'] = 95
d['Lisa'] = 85
d['Bart'] = 59
for key,value in d.items():
print(key.title() + ": " + str(value))
d = OrderedDict()
d['Adam'] = 95
d['Lisa'] = 85
d['Bart'] = 59
for key,value in d.items():
print(key.title() + ": " + str(value))
2018-08-02
#Enter a code
print 45678+0x12fd2
print 'Learn Python in imooc'
print 100<90,0xff==255
print 45678+0x12fd2
print 'Learn Python in imooc'
print 100<90,0xff==255
2018-08-02