def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2020-03-18
def square_of_sum(L):
sum=0
for i in L:
sum+=i**2
return sum
print (square_of_sum([1, 2, 3, 4, 5]))
print(square_of_sum([-5, 0, 5, 15, 25]))
#简洁代码
sum=0
for i in L:
sum+=i**2
return sum
print (square_of_sum([1, 2, 3, 4, 5]))
print(square_of_sum([-5, 0, 5, 15, 25]))
#简洁代码
2020-03-17
L=[]
sum=0
a=1
while a<=100:
b=a*a
sum+=b
L.append(b)
a+=1
print(sum)
L=[]
sum=0
a=1
for a in range(101):
b=a*a
L.append(b)
sum+=b
a+=1
print(sum)
#if语句我实现不了该题
sum=0
a=1
while a<=100:
b=a*a
sum+=b
L.append(b)
a+=1
print(sum)
L=[]
sum=0
a=1
for a in range(101):
b=a*a
L.append(b)
sum+=b
a+=1
print(sum)
#if语句我实现不了该题
2020-03-17
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print(s)
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print(s)
2020-03-17
s = set([1, 2, 3])
s_1={1,2,3}
print(s,type(s))
print(s_1,type(s_1))
两种都是集合的表达方式,不过最终打印出的形式是{1,2,3}
s_1={1,2,3}
print(s,type(s))
print(s_1,type(s_1))
两种都是集合的表达方式,不过最终打印出的形式是{1,2,3}
2020-03-17
for x in [1,2,3,4,5,6,7,8,9]:
for y in [1,2,3,4,5,6,7,8,9]:
if x<y:
print(str(x)+str(y))
for y in [1,2,3,4,5,6,7,8,9]:
if x<y:
print(str(x)+str(y))
2020-03-17
sum = 0
x = 1
n = 1
while True:
sum+=x
n+=1
x=2**(n-1)
if n>20:
break
print( sum)
sum = 0
x = 1
n = 1
while True:
sum+=x*(2**(n-1))
n+=1
if n>20:
break
print( sum)
x = 1
n = 1
while True:
sum+=x
n+=1
x=2**(n-1)
if n>20:
break
print( sum)
sum = 0
x = 1
n = 1
while True:
sum+=x*(2**(n-1))
n+=1
if n>20:
break
print( sum)
2020-03-17