Day_10_Weekend_Homework_Answer
''''''
import random
''' 简答题 '''
# 1, Python中的循环有几种:
# for-in, while
# 2, Python的数据类型有哪些:
# int,float,str, bool, list, tuple, None, dict, set, bytes
# 3, Python中空类型特殊值是:
# None
# 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
'''
x, *y, z = 1,2,3,4
a,b,*c = (1,2,3,4,5)
print(a, b, c) # 1 2 [3, 4, 5]
# 5, 列举至少5种常用的内置函数,并解释函数的作用:
# print, sum, min, max, abs
# 6,判断下面变量名不正确的有哪些:
# ABC, aBC, a-bc, a_bc, _num123, 123num, NUM123, num_123,
# True, false, true1, false0, print, id, __id__, python
# => a-bc, 123num, True
# 7,列举列表list中的至少6个函数,且说明每个函数对应的作用
# append, insert, extend, clear, pop, remove, sort, reverse, copy, index,
# 8,列举字典dict中的至少3个函数,且说明每个函数对应的作用
# get, pop(key), update, clear, keys, values, items, copy
''' 编程题 '''
# 1, 将列表中元素去重, 使用至少2种方式
# 方式一:
l = [1,1,11,2,2,23,3,4,5,6,6,6,4,4,5,]
print(list(set(l)))
# 方式二:
l = [1,1,11,2,2,23,3,4,5,6,6,6,4,4,5,]
l2 = []
for n in l:
if n not in l2:
l2.append(n)
l = l2
print(l)
# 2、编写一个函数gcd(x,y) 求最大公约数,编写一个函数lcm(x,y)求最小公倍数。
# 最大公约数
def gcd(x, y):
for n in range(min(x,y), 0, -1):
if x%n==0 and y%n==0: