# Enter a code
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for v1 in L:
if v1 in S:
S.remove(v1)
else:
S.add(v1)
print(S)
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for v1 in L:
if v1 in S:
S.remove(v1)
else:
S.add(v1)
print(S)
2021-03-19
names1= []
names2=['Jenny', 'Ellena', 'Alice', 'Candy', 'David', 'Hally', 'Bob', 'Isen', 'Karl']
names1_set=set(names1)
#方法一
for v in names2:
names1_set.add(v)
print(names1_set)
#方法二
names1_set.update(names2)
print(names1_set)
names2=['Jenny', 'Ellena', 'Alice', 'Candy', 'David', 'Hally', 'Bob', 'Isen', 'Karl']
names1_set=set(names1)
#方法一
for v in names2:
names1_set.add(v)
print(names1_set)
#方法二
names1_set.update(names2)
print(names1_set)
2021-03-19
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
for x in s1:
if s1.isdisjoint(s2) == False:
print(x)
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
for x in s1:
if s1.isdisjoint(s2) == False:
print(x)
2021-03-19
# Enter a code
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
names.insert(0,'Ellena')
names.pop(2)
names[-1] = 'Bob'
print(names)
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
names.insert(0,'Ellena')
names.pop(2)
names[-1] = 'Bob'
print(names)
2021-03-17
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
for key in d:
value=d[key]
for score in value:
print(key,score)
for key in d:
value=d[key]
for score in value:
print(key,score)
2021-03-17
# Enter a code
# -*- coding: UTF-8 -*-
# Enter a code
# -*- coding: UTF-8 -*-
#age = int(input('請(qǐng)輸入年齡 '))
age = 6
if age >= 18:
print('成年人')
elif 6 <= age <= 18:
print('青少年')
elif 3 <= age <= 6:
print('小孩子')
elif age <= 3:
print('嬰兒')
else:
print('出現(xiàn)錯(cuò)誤')
# -*- coding: UTF-8 -*-
# Enter a code
# -*- coding: UTF-8 -*-
#age = int(input('請(qǐng)輸入年齡 '))
age = 6
if age >= 18:
print('成年人')
elif 6 <= age <= 18:
print('青少年')
elif 3 <= age <= 6:
print('小孩子')
elif age <= 3:
print('嬰兒')
else:
print('出現(xiàn)錯(cuò)誤')
2021-03-17
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
l=[50, 61, 66],[80, 61, 66],[88, 75, 90]
print(l[0])
n=0
for v2 in d:
d[v2] = l[n]
print(d,end='\n')
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
l=[50, 61, 66],[80, 61, 66],[88, 75, 90]
print(l[0])
n=0
for v2 in d:
d[v2] = l[n]
print(d,end='\n')
2021-03-17
num=0
sum=0
while num<=1000:
if num%2==0:
sum+=num
num+=1
else:
num += 1
continue
print('sum=',sum)
sum=0
while num<=1000:
if num%2==0:
sum+=num
num+=1
else:
num += 1
continue
print('sum=',sum)
2021-03-16
s1 = 'ABC'
s2 = '123'
s3 = 'abc'
for x in s1:
for y in s2:
for z in s3:
print(x+y+z)
s2 = '123'
s3 = 'abc'
for x in s1:
for y in s2:
for z in s3:
print(x+y+z)
2021-03-16
# Enter a code
a = r'''"To be,or not to be":that is the question.
Whether it's nobler in the mind to suffer.'''
print (a)
a = r'''"To be,or not to be":that is the question.
Whether it's nobler in the mind to suffer.'''
print (a)
2021-03-15
# Enter a code
# encoding=utf-8
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
num = 2
while num > 0:
num -= 1
name = 'Alice'
if name in d:
d.pop(name)
print(d)
else:
print('{}沒有在d里面'.format(name))
# encoding=utf-8
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
num = 2
while num > 0:
num -= 1
name = 'Alice'
if name in d:
d.pop(name)
print(d)
else:
print('{}沒有在d里面'.format(name))
2021-03-14