num=0
sum=0
while True:
if num>1000:
break
sum=sum+num
num+=2
print(sum)
#这样也可以
sum=0
while True:
if num>1000:
break
sum=sum+num
num+=2
print(sum)
#这样也可以
2021-04-04
a = r''''\"To be,or not to be\":that is the question.\n
Whether it\'s nobler in the mind to suffer.'
'''
print(a)
Whether it\'s nobler in the mind to suffer.'
'''
print(a)
2021-04-04
答案应该是:
s1 = 'ABC'
s2 = '123'
s3='xyz'
for z in s3:
for x in s1:
for y in s2:
print(x + y+ z);
print(x + z+ y);
print(y + x+ z);
print(y + z+ x);
print(z + x+ y);
print(z + y+ x);
s1 = 'ABC'
s2 = '123'
s3='xyz'
for z in s3:
for x in s1:
for y in s2:
print(x + y+ z);
print(x + z+ y);
print(y + x+ z);
print(y + z+ x);
print(z + x+ y);
print(z + y+ x);
2021-04-04
# Enter a code
L = [75, 92, 59, 68, 99]
sum = 0.0
for s in L:
sum = sum + s
ave = sum / len(L)
print(ave)
L = [75, 92, 59, 68, 99]
sum = 0.0
for s in L:
sum = sum + s
ave = sum / len(L)
print(ave)
2021-04-03
# Enter a code
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
names.append('Zero')
names.insert(-2,'Gen')
names.insert(-2,'Phoebe')
print(names)
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
names.append('Zero')
names.insert(-2,'Gen')
names.insert(-2,'Phoebe')
print(names)
2021-04-02
L = [95.5, 85, 59, 66, 72]
L.sort(reverse = False)
print('first: ',L[-1])
print('second: ',L[-2])
print('third: ',L[-3])
L.sort(reverse = False)
print('first: ',L[-1])
print('second: ',L[-2])
print('third: ',L[-3])
2021-04-02
# Enter a code
L = [95.5, 85, 59, 66, 72]
L.sort(reverse = True)
print('first: ',L[0])
print('second: ',L[1])
print('third: ',L[2])
L = [95.5, 85, 59, 66, 72]
L.sort(reverse = True)
print('first: ',L[0])
print('second: ',L[1])
print('third: ',L[2])
2021-04-02
# Enter a code
courses = ['Chinese', 'Match', 'English']
scores = [92, 75, 99]
oder = [0, 1, 2]
print ('Alice\' score: ')
for i in oder:
print (courses[i],': ',scores[i])
courses = ['Chinese', 'Match', 'English']
scores = [92, 75, 99]
oder = [0, 1, 2]
print ('Alice\' score: ')
for i in oder:
print (courses[i],': ',scores[i])
2021-04-02
# Enter a code
def list_a(a):
result = 0
for i in a:
result += i*i
return result
L = [10,20]
print list_a(L)
def list_a(a):
result = 0
for i in a:
result += i*i
return result
L = [10,20]
print list_a(L)
2021-03-31
# Enter a code
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for i in L:
if i in S:
S.remove(i)
else:
S.add(i)
print S
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for i in L:
if i in S:
S.remove(i)
else:
S.add(i)
print S
2021-03-31
# Enter a code
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
name_set = set(names)
a = 'Alice'
for i in name_set:
if a.lower() in i.lower():
print "True"
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
name_set = set(names)
a = 'Alice'
for i in name_set:
if a.lower() in i.lower():
print "True"
2021-03-31
d = {'Alice': [50, 61, 66, 1], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
a = 0
for x in d.keys():
a += 1
for y in d[x]:
a += 1
print a
a = 0
for x in d.keys():
a += 1
for y in d[x]:
a += 1
print a
2021-03-31
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
for x, y in d.items():
for i in y:
print x, i
for x, y in d.items():
for i in y:
print x, i
2021-03-31
# Enter a code
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
x = 'Alice'
y = 'old_Alice'
if x in d:
d[y] = d[x]
d[x] = 60
print d
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
x = 'Alice'
y = 'old_Alice'
if x in d:
d[y] = d[x]
d[x] = 60
print d
2021-03-31