sum = 0
x = 1
while x<50:
sum=sum+(2*x-1)
x=x+1
print sum
x = 1
while x<50:
sum=sum+(2*x-1)
x=x+1
print sum
2019-04-13
def toUppers(L):
return [x.upper() for x in L if isinstance(x, str) ]
print toUppers(['Hello', 'world', 101])
return [x.upper() for x in L if isinstance(x, str) ]
print toUppers(['Hello', 'world', 101])
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum*1.0/len(d)
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum*1.0/len(d)
2019-04-13
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in zip(range(1,5),L):
print index, '-', name
for index, name in zip(range(1,5),L):
print index, '-', name
print r'''"To be, or not to be":that is the question.
Whether it's nobler in the mind to suffer.'''
Whether it's nobler in the mind to suffer.'''
2019-04-13
如果是‘hello,’‘python’,则hello,python的逗号之后没有空格,如果是‘hello,’,‘python’,逗号之后还会有一个空格;
2019-04-13
def firstCharUpper(s):
return s[:1].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[:1].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2019-04-12
# 末项
x100 = x1 + (n - 1) * d
# 方法一
s = (x1 + x100) * n / 2
# 方法二
s = n * x1 + n * (n - 1) / 2 * d
x100 = x1 + (n - 1) * d
# 方法一
s = (x1 + x100) * n / 2
# 方法二
s = n * x1 + n * (n - 1) / 2 * d
2019-04-12
def average(*args):
if len(args)!=0:
s=sum(args)*1.0/len(args)
return s
else:
return 0.0
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args)!=0:
s=sum(args)*1.0/len(args)
return s
else:
return 0.0
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2019-04-11