"""
简答题
"""
# 1, Python中的循环有哪几种,一般用于什么场景:
'''
for 循环:已知循环次数
while 循环 :死循环 已知循环次数 未知循环次数
'''
# 2, Python的数据类型有哪些,请列举:
'''
int 整型
float 浮点型
str 字符串
NoneType
bool 布尔类型
bytes 字节类型
list 列表
tuple 元组
dict 字典
set 集合
complex 复数类型
'''
# 3, Python中空类型的值是:
'''
int 整型 0
float 浮点型 0.0
str 字符串 空字符串
NoneType None
bool 布尔类型 False
list 列表 []
tuple 元组 ()
dict 字典 {}
set 集合 set()
'''
# 4, 判断下列赋值方式正确与否(True or False)
'''
x = y = z = 1 => True
x=1, y=2 => False
x, *y, z = 1,2,3,4 => True
x, y, z = (1,2,3) => True
'''
# 5, 列举至少5种常用的内置函数,并解释函数的作用:
'''
abs():绝对值,正数返回本身,负数返回它的相反数
print(): 输出
input():输入
int() : 将数据转换为整型,这个数据需要由数字(0-9)组成
str() : 将数据转换为字符串
sum() : 求和
min() : 最小值
max() : 最大值
'''
# 6,判断下面变量名不正确的有哪些:
# ABC, aBC, a-bc, a_bc, _num123, 123num, NUM123, num_123,
# True, false, true1, false0, print, id, __id__, python
'''
变量名不正确
a-bc 123num True
可以但不建议
print
'''
# 7,列举列表list中的至少6个常用函数,且说明每个函数对应的作用
'''
list.sort() 排序,默认是升序
list.index(n) 查找元素对应的下标/索引值,返回找到的第一个元素的下标/索引
list.insert(i,n) 在下标i的未知插入元素n
list.extend(iterable) 在列表的末尾追加可迭代对象
list.count(n) 统计元素n在列表中出现的次数
list.reverse() 逆序,倒序
list.clear() 清空列表
list.remove(n) 移除第一个出现在列表中的元素n
list.append(n) 在列表的末尾添加元素n
list.copy() 拷贝,复制,浅拷贝
list.pop() 弹出(删除并打印),不写参数的时候一般默认弹出最后一个元素
len(list) 打印列表长度
min(list) 获取列表的最小值
max(list) 获取列表的最大值
'''
# 8,列举字典dict中的至少3个常用函数,且说明每个函数对应的作用
'''
dict.pop() 弹出(删除并打印),必须要至少给一个参数,这个参数是字典的键key,如果给的不是键,会报错
dict.copy() 拷贝,复制,浅拷贝
dict.clear() 清空字典
dict.get() 获取字典值 dict.get(key, '其他值') 当前键不存在时设置返回其他值
dict.values() 获取字典值
dict.keys() 获取字典键
dict1.update(dict2) 合并 将字典dict2的键值对合并到字典dict1中
dict1.items() 获取字典的键值对
'''
''' 编程题 '''
# 1, 将列表中元素去重
nums = [2, 3, 3, 3, 5, 3, 6, 6, 5, 5, 4]
new_nums = []
for n in nums:
if n not in new_nums:
new_nums.append(n)
print(new_nums)
# 2、输入2个数x和y,求他们的最大公约数, 如:12和8的最大公约数是:4
x = int(input("x: "))
y = int(input("y: "))
min1 = min(x, y)
max1 = max(x, y)
n = 1
for i in range(1, min1+1):
if max1 % i == 0 and min1 % i =