def firstCharUpper(s):
a=s[0:1].upper()
b=s[1:]
return a+b
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
a=s[0:1].upper()
b=s[1:]
return a+b
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2020-06-18
def average(*args):
if len(args) ==0:
return 0.0
else:
sum = 0
n =0
for s in args:
sum = sum +s
n = len(args)
return sum * 1.0 / n
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args) ==0:
return 0.0
else:
sum = 0
n =0
for s in args:
sum = sum +s
n = len(args)
return sum * 1.0 / n
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2020-06-18
def greet(x='world'):
print 'Hello,',x,'.'
greet()
greet('Bart')
print 'Hello,',x,'.'
greet()
greet('Bart')
2020-06-18
def move(n, a, b, c):
if n==1:
print a,'-->',c
else:
move(n-1,a,c,b)
# print a,'-->',b
print a,'-->',c
move(n-1,b,a,c)
# a-->b a-->c b-->c
move(4, 'A', 'B', 'C')
做不出来的时候好难,做出来理解了就简单了。
if n==1:
print a,'-->',c
else:
move(n-1,a,c,b)
# print a,'-->',b
print a,'-->',c
move(n-1,b,a,c)
# a-->b a-->c b-->c
move(4, 'A', 'B', 'C')
做不出来的时候好难,做出来理解了就简单了。
2020-06-18
最新回答 / 任长风3321202
第一个用print 'end’指令告诉用户 end 当运行程序之后第二个没有反馈给用户end文字当运行完程序。Score就是英语 分数 的意思。
2020-06-18
sum = 0
x = 1
n = 1
while True:
sum=sum+x
x=2*x
n=n+1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum=sum+x
x=2*x
n=n+1
if n > 20:
break
print sum
2020-06-17
L = [75, 92, 59, 68]
sum = 0
sum1 = 0
avg = 0
for a in L:
sum = sum+a
sum1 = sum1+1
avg = sum/sum1
print (avg)
sum = 0
sum1 = 0
avg = 0
for a in L:
sum = sum+a
sum1 = sum1+1
avg = sum/sum1
print (avg)
2020-06-15
def square_of_sum(L):
arr = []
for n in L:
arr.append(n*n)
return sum(arr)
print (square_of_sum([1, 2, 3, 4, 5]))
print (square_of_sum([-5, 0, 5, 15, 25]))
arr = []
for n in L:
arr.append(n*n)
return sum(arr)
print (square_of_sum([1, 2, 3, 4, 5]))
print (square_of_sum([-5, 0, 5, 15, 25]))
2020-06-15
L = []
n=1
for i in range(1,101):
L.append(i*n)
n=n+1
print(sum(L))
print(L)
n=1
for i in range(1,101):
L.append(i*n)
n=n+1
print(sum(L))
print(L)
2020-06-15
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for lname in L:
if lname in s:
s.remove(lname)
else:
s.add(lname)
print(s)
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for lname in L:
if lname in s:
s.remove(lname)
else:
s.add(lname)
print(s)
2020-06-15
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 10*x+y
else:continue
for y in [0,1,2,3,4,5,6,7,8,9]:
if x < y:
print 10*x+y
else:continue
2020-06-14