s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
n=0
while n<4:
if L[n] in s:
s.remove(L[n])
else:
s.add(L[n])
n=n+1
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
n=0
while n<4:
if L[n] in s:
s.remove(L[n])
else:
s.add(L[n])
n=n+1
print s
2020-03-06
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/len(d)
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
2020-03-06
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for v in d.values():
sum+=v
print sum/len(d)
sum = 0.0
for v in d.values():
sum+=v
print sum/len(d)
2020-03-06
def firstCharUpper(s):
t = s.title()
return t
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
t = s.title()
return t
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2020-03-06
已采纳回答 / 慕瓜2387236
print语句不要与continue语句平齐,因为Python中对于代码缩进有严格的控制,如果平齐,则代表是在同一个代码块中,你代码中print就代表是在if代码块中执行,而print在continue后面,则你的print永远不会被执行,把print与if平齐就好了。
2020-03-06
def square_of_sum(L):
s=[]
for i in L:
x = i*i
s.append(x)
return sum(s)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
s=[]
for i in L:
x = i*i
s.append(x)
return sum(s)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2020-03-05