|
| 1 | +# This is for advanced Python programmers, who want something a little bit saltier. |
| 2 | +# Create this Fibonary Bits In Action! Python program using a single print() function. |
| 3 | +# Use the backslash '\' to create line breaks within the print() function. |
| 4 | + |
| 5 | +# Type and execute/run this Python program example below and see what happens. |
| 6 | + |
| 7 | +# Note: after you save your file, you must double click this file to view it's cool coloured |
| 8 | +# text and layout. |
| 9 | + |
| 10 | +# Created by Joseph C. Richardson |
| 11 | + |
| 12 | +import os;os.system('title fibonary bits in action!'.title()) |
| 13 | +from time import sleep as delay |
| 14 | + |
| 15 | +red='\x1b[31m' |
| 16 | +green='\x1b[32m' |
| 17 | +blue='\x1b[34m' |
| 18 | +yellow='\x1b[33m' |
| 19 | +purple='\x1b[35m' |
| 20 | +white='\x1b[37m' |
| 21 | + |
| 22 | +title_text=f'fibonary bits in action!'.title(),'fibonacci natural number sequence'.title() |
| 23 | +text=('binary digits: ','octal digits: ','hexadecimal digits: ','decimal digits: ', |
| 24 | + 'fibonacci digits: '.title()) |
| 25 | + |
| 26 | +lb='\n';lbb='\n\n';elb='=\n';eq='=';sp=' ' |
| 27 | + |
| 28 | +num1=0;num2=1 |
| 29 | +fib=[num1,num2] |
| 30 | + |
| 31 | +pause=1 |
| 32 | + |
| 33 | +input() |
| 34 | +while True: |
| 35 | + os.system('cls') |
| 36 | + num3=num1+num2 |
| 37 | + fib.append(num3) |
| 38 | + num1=num2;num2=num3 |
| 39 | + |
| 40 | + b=f'{num3:b}';o=f'{num3:o}' |
| 41 | + x=f'{num3:X}';d=f'{num3:d}' |
| 42 | + |
| 43 | + print(white+lb+sp*16+title_text[0],lb+red,lb,sp*2,len(b),green+text[0].title()+\ |
| 44 | + yellow+b+blue,elb,sp*2+green+red,len(o),green+text[1].title()+yellow+\ |
| 45 | + o+blue,elb,sp*2+green+red,len(x),green+text[2].title()+yellow+x+\ |
| 46 | + blue,eq,green,lb,sp*2+red,len(d),green+text[3].title()+blue+eq,yellow+\ |
| 47 | + d+lbb+white+sp*11+title_text[1]+lbb+green+sp*4+text[4]+yellow+f'{num3:,}') |
| 48 | + delay(pause) |
0 commit comments