柠檬班学员面试遇到的笔试题!!!
出招吧各位大佬!
柠檬班学员面试遇到的笔试题!!!
出招吧各位大佬!
if name == 'main':
num = int(input('input a number:'))
newLi = []
li = [x for x in range(1,num,2)]
if num % 2 != 0:
newLi = li + [num] +li[::-1]
else:
newLi = li + li[::-1]
print(newLi)
for i in newLi:
print(i*'*')
# 镜像星星金字塔
def mirror_star_pyramid(n):
i = 1# 给定初始值
star_list1 = []# 存正金字塔每一层元素
star_list2 = []# 存倒金字塔每一层元素
while i <= n:
star_list1.append(' '*((n-i)//2) + '*'*i + ' '*((n-i)//2))
# n的奇偶性将决定倒金字塔的元素是跟正金字塔一样还是比正金字塔少一层
if n % 2:
star_list2.append(' '*((i+1)//2) + '*'*(n-i-1) + ' '*((i+1)//2))
else:
star_list2 = star_list1[::-1]
i += 2
for each in star_list1:print(each)
for each in star_list2:print(each)
if __name__ == '__main__':
mirror_star_pyramid(5)
mirror_star_pyramid(6)
欢迎来到testingpai.com!
注册 关于