Use code verification "name" is in the dictionary keys?
info = { 'name': 'Gang egg', 'hobby': 'hammer', 'age': '18', ... 100} key-value pairs
info = {'name':'王刚蛋','hobby':'铁锤','age':'18'} info_lis = list(info.keys()) if 'name' in info_lis: print("'name'在字典的键中。") else: print('没有此键')
Use code verification "alex" if the value of the dictionary?
info = {'name':'王刚蛋','hobby':'铁锤','age':'18',...100个键值对}
info = {'name':'王刚蛋','hobby':'铁锤','age':'18',1:'alex'} info_lis = list(info.values()) if 'alex' in info_lis: print("'alex'在字典的值中。") else: print('没有此值。')
There follows
v1 = {'武沛齐','李杰','太白','景女神'} v2 = {'李杰','景女神}
Please get v1 and v2 and the intersection of output
Please get v1 and v2 union and output
Please give v1 and v2 and the output differential current
Please give v2 and v1 and difference output
v1 = {'武沛齐','李杰','太白','景女神'} v2 = {'李杰','景女神'} # - 请得到 v1 和 v2 的交集并输出 print(v1 & v2) # - 请得到 v1 和 v2 的并集并输出 print(v1 | v2) # - 请得到 v1 和 v2 的 差集并输出 print(v1 - v2) # - 请得到 v2 和 v1 的 差集并输出 print(v2 - v1)
Cycle prompts the user, and inputs the content added to the list (if the input is stopped cycle n or N)
lis = [] while 1: msg = input('请输入:(N/n退出)').strip() if msg.upper() == 'N':break else: lis.append(msg) print('*'*30) print(lis) print('*'*30)
Cycle prompts the user, and inputs the contents to the collection (n if the input is stopped or N cycle)
set1 = set() while 1: msg = input('请输入:(N/n退出)').strip() if msg.upper() == 'N':break else: set1.add(msg) print('*'*30) print(set1) print('*'*30)
Write code to achieve
v1 = {'alex','武sir','肖大'} v2 = [] # 循环提示用户输入,如果输入值在v1中存在,则追加到v2中,如果v1中不存在,则添加到v1中。(如果输入N或n则停止循环)
v1 = {'alex','武sir','肖大'} v2 = [] while 1: print('*'*30) msg = input('请输入:(N/n退出)').strip() if msg.upper() == 'N':break elif msg in v1: v2.append(msg) else: v1.add(msg) print('*'*30) print(v1) print(v2)
Using a loop to print out at the results:
*
**
***
****
*****
for i in range(1,6):
print('*'*i)
****
***
**
*
for i in range(-5,0):
print('*'* -i)
*
***
*****
*******
*********
for i in range(1,10,2):
print('*'* i)
- Knock seven game from a start count. 7 or 7 encounter multiple (17, 27 does not contain this number) to be. In the table programming to complete knock knock ⼀ VII. ⼀ given arbitrary number n from a start count the number n to end. each number on the list, a multiple of 7 or 7 appears in the number of process (17, 27 does not contain this number). Add an then to the list a 'bang'
For example, input START 10. lst = [1, 2, 3, 4, 5, 6, 'bang', 8, 9, 10]
lis = []
while 1:
n = input('请输入任意一个数字:(Q/q退出)').strip()
if n.upper() == 'Q':break
for i in range(1,int(n)+1):
if i % 7 == 0:
lis.append('咣')
else:
lis.append(i)
print(f'当前数字为:{i},结果为:{lis}')
print('*'* 60)
print(f'输入的数字是:{n}')
print(f'结果为:{lis}')