背景
朋友面试凉了,被我无情嘲笑,直到他把题给了我。。。
def task1(str_list: list):
for i in str_list:
print(i.upper())
# return [i.upper() for i in str_list]
a = ['qIqiqqq@@@1', 'ily']
task1(a)
def task2(fun):
print(fun.__doc__)
task2(int)
def task3(str_list: list):
print(str_list[::-1])
task3(['a', 'b', 'c', 'd'])
def task4(num: int):
tmp = str(num)
if num % 3 == 0:
if num % 5 == 0:
tmp = 'FizzBuzz'
return {num: tmp}
tmp = 'Fizz'
return {num: tmp}
elif num % 5 == 0:
tmp = 'Buzz'
return {num: tmp}
return {num: tmp}
print(task4(15))
def task5(num: int):
# 题目应该有点问题,应该是(0: L] 这个区间,不然结果肯定是0了, 就可以理解为是求num的阶乘后面有几个0
# 思路; 决定结果末尾0的个数其实就是求5出现的次数,祺中像25 = 5 * 5、50 = 5 * 5 *2 这种5出现了多次要多次统计
result = 0
i = 5
while num >= i:
result += num // i
i = i * 5
return result
print(task5(100))
def task6(num: int):
tmp = 200 % num
return 200 - tmp
print(task6(17))
def task8(num: int):
tmp = bin(num)
print(tmp)
result = 0
for i in str(tmp):
if i == '1':
result += 1
return result
print(task8(100))
def task9(str1: str):
return str1.swapcase()
print(task9('QiQi'))
def task10(num_list: list):
num_list.sort()
if num_list[0] + num_list[1] > num_list[2]:
return 'yes'
return 'no'
print(task10([1, 3, 2]))
print(task10([3, 5, 4]))
def task11(num_list: list):
# 思路; 两数的最小公倍数就是两数的乘积除以他们的最大公约数
small_num = min(num_list)
big_num = max(num_list)
# 原来两数的积
tmp = small_num * big_num # 还没写完。。。
第7题第11题没做出来,我丢!后面还有10多题,明日继续!!!