打印菱形 1.补空格 a=int(input( ‘ input a odd number ‘ ))b =a//2 for i in range(-b,b+1 ): print ( ‘ ‘ *abs(i)+ ‘ * ‘ *(a-2* abs(i)))input a odd number 7 * *** ************ ***** *** * 2.居中对齐 b=7 c =b//2 for i in ra
打印菱形
1.补空格
a=int(input(‘input a odd number>>>‘)) b=a//2 for i in range(-b,b+1): print(‘ ‘*abs(i)+‘*‘*(a-2*abs(i))) input a odd number>>>7 * *** ***** ******* ***** *** *
2.居中对齐
b=7 c=b//2 for i in range(-c,c+1): a=b-abs(i)*2 print(‘{:^{}}‘.format(‘$‘*a,b)) $ $$$ $$$$$ $$$$$$$ $$$$$ $$$ $
打印对顶三角形
b=7 c=b//2 for i in range(-c,c+1): a=abs(i)*2+1 print(‘{:^{}}‘.format(‘$‘*a,b)) $$$$$$$ $$$$$ $$$ $ $$$ $$$$$ $$$$$$$
打印闪电
a=7 b=a//2 c=a-b for i in range(-b,c): if i>0: print(‘ ‘*b+(c-i)*‘$‘) elif i<0: print(‘ ‘*-i+(c+i)*‘$‘) else: print(‘$‘*a) $ $$ $$$ $$$$$$$ $$$ $$ $
打印斐波那契数列
a=1 b=1 c=a+b s=2 while True: s+=1 a=b b=c c=a+b print(c) if s==15:break
a=0 b=1 index=0 print(‘fib({})={}‘.format(index,a)) index+=1 print(‘fib({})={}‘.format(index,b)) while True: c=a+b index+=1 if c>100: break print(‘fib({})={}‘.format(index,c)) a=b b=c fib(0)=0 fib(1)=1 fib(2)=1 fib(3)=2 fib(4)=3 fib(5)=5 fib(6)=8 fib(7)=13 fib(8)=21 fib(9)=34 fib(10)=55 fib(11)=89