def firstCharUpper(s):
return '%s'%s[0:1].upper()+'%s'%s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return '%s'%s[0:1].upper()+'%s'%s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2019-08-15
def average(*args):
if not args:
print 0.0
else:
print sum(args)*1.0/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if not args:
print 0.0
else:
print sum(args)*1.0/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2019-08-15
def greet(n = 'world'):
print 'hello,%s.'%n
greet()
greet('Bart')
print 'hello,%s.'%n
greet()
greet('Bart')
2019-08-15
sum = 0
x = 1
while x<100:
sum=sum+x
x=x+2
print sum
x = 1
while x<100:
sum=sum+x
x=x+2
print sum
2019-08-15
#-*- coding:utf-8 -*-
def move(n, a, b, c):
if n==1:
print a,'-->',c
return
move(n-1, a, c, b)
move(1, a, b, c)
move(n-1, b, a, c)
print move(4, 'a', 'b', 'c')
def move(n, a, b, c):
if n==1:
print a,'-->',c
return
move(n-1, a, c, b)
move(1, a, b, c)
move(n-1, b, a, c)
print move(4, 'a', 'b', 'c')
2019-08-14
age=8
if age>=10:
print 'teggner'
elif age>=8:
print 'adult'
else:
print 'kid'
是因为第一个if语句为真,直接忽略后面的语句,所以我们可以这样实现
if age>=10:
print 'teggner'
elif age>=8:
print 'adult'
else:
print 'kid'
是因为第一个if语句为真,直接忽略后面的语句,所以我们可以这样实现
2019-08-14
L1 = [1,2,3,4]
L2 = ["a","b","c","d"]
x = 0
d={
0:"name",
}
while x<len(L1):
d[L1[x]]=L2[x]
x+=1
print d[x]
L2 = ["a","b","c","d"]
x = 0
d={
0:"name",
}
while x<len(L1):
d[L1[x]]=L2[x]
x+=1
print d[x]
2019-08-14
x1 = 1
d = 3
n = 100
x100 = x1+d*(n-1)
s =(x1+x100)*n/2
print s
数学角度可以算出来,但是我觉得这个应该在学了循环以后再做更有意义
d = 3
n = 100
x100 = x1+d*(n-1)
s =(x1+x100)*n/2
print s
数学角度可以算出来,但是我觉得这个应该在学了循环以后再做更有意义
2019-08-14