当前位置:网站首页>Exercise "product": self made colorful Prompt string display tool (for loop and if condition judgment)
Exercise "product": self made colorful Prompt string display tool (for loop and if condition judgment)
2022-06-30 00:44:00 【Dreamy spirit_ cq】
Python Official website :https://www.python.org/
Free: Big coffee free “ Bible ” course 《 python Complete self study course 》, It's not just the basics ……
- My CSDN Home page 、My HOT Bo 、My Python Study personal memos
- A good writer recommends 、 Laoqi classroom
Self study is not a mysterious thing , A person's self-study time is always longer than that in school , There are always more times when there are no teachers than when there are teachers .
—— Hua Luogeng

- 1、 Code running effect
- 2、" Colorful Prompt string display tool " function code
- 3、 This exercise complete source code
When I did the exercise , I wanted to make a loading progress bar , It didn't work out , But made this thing .
Code running effect
Code running video effects dynamic link :http://t.csdn.cn/sV20r

Current scene “ Random ” To the same background color , That's why “ Blanking ” The false appearance of .python 033 Color output control ( Click the blue text to jump to view the details ) Yes black 、 white 、 red 、 green 、 green 、 blue 、 purple seven colors of the spectrum , Cancel background color “ Random ”, This can be eliminated “bug”. My homemade colorful printing tool color, Click jump to view the detailed usage , this paper “ Gadgets ” That is to use color“ Add color ” Of .
Colorful Prompt string shows the function code
def show_tip(string, num, width):
''' Colorful prompt character display string: tip character string n: Display duration (n×0.4 second ) width: Display width (≤50)( Calculated in English characters )'''
s = string
if len(s)>50:
s = a[50]
l = system('clear') # Linux Clear the screen .
print('\n'*3) # Print three blank lines .
for i in range(num):
flag = choice(range(7)) # flag Random assignment 0、1、2、3、4、5.
if flag == 0: # Red .
print(color(s,'f_red').center(width, '~'), end='\r')
elif flag == 1: # green .
print(color(s,'f_green').center(width, '~'), end='\r')
elif flag == 2: # Blue .
print(color(s,'f_blue').center(width, '~'), end='\r')
elif flag == 3: # yellow .
print(color(s,'f_yellow').center(width, '~'), end='\r')
elif flag == 4: # violet .
print(color(s,'f_purple').center(width, '~'), end='\r')
elif flag == 5: # gray .
print(color(s,'f_gray').center(width, '~'), end='\r')
elif flag == 6: # gray .
print(color(s,'f_black').center(width, '~'), end='\r')
sleep(0.4) # Pause num second .
print() # Print blank lines .

This exercise complete source code
#!/sur/bin/nve python
# coding: utf-8
''' filename = 'color_tip.py' author = ' The dream spirit _cq' time = '2022-06-27' '''
from time import sleep # load time Module pause method .
from os import system # load Linux Command container , Easy code execution Linux command .
from random import choice # Loading random number module random selection method .
from python_color import color # Load the self-made color control printing tool module .
def show_tip(string, num, width):
''' Colorful prompt character display string: tip character string n: Display duration (n×0.4 second ) width: Display width (≤50)( Calculated in English characters )'''
s = string
if len(s)>50:
s = a[50]
l = system('clear') # Linux Clear the screen .
print('\n'*3) # Print three blank lines .
for i in range(num):
flag = choice(range(7)) # flag Random assignment 0、1、2、3、4、5.
if flag == 0: # Red .
print(color(s,'f_red').center(width, '~'), end='\r')
elif flag == 1: # green .
print(color(s,'f_green').center(width, '~'), end='\r')
elif flag == 2: # Blue .
print(color(s,'f_blue').center(width, '~'), end='\r')
elif flag == 3: # yellow .
print(color(s,'f_yellow').center(width, '~'), end='\r')
elif flag == 4: # violet .
print(color(s,'f_purple').center(width, '~'), end='\r')
elif flag == 5: # gray .
print(color(s,'f_gray').center(width, '~'), end='\r')
elif flag == 6: # gray .
print(color(s,'f_black').center(width, '~'), end='\r')
sleep(0.4) # Pause num second .
print() # Print blank lines .
if __name__ == '__main__':
num = 50 # 0.4×n second “ Seven colors ” Prompt character .
s = ' Colorful Prompt string display ' # Set Prompt string
width = 50 # Prompt string display width setting .
show_tip(s, num, 50) # Call the function to display information .

My Up and Down:
__ Last one :__ 《 Siddhartha 》: The book of life , Can often ruminate__ Next :__ CSV File format —— It is convenient to use the smallest data transmission method
my HOT Bo :
- practice : Calculation of bank compound interest ( use for Solve a junior high school problem in a circular way )(1050 read )
- pandas Data type DataFrame(1308 read )
- Is it difficult for someone in the class to have the same birthday as me ?( probability probability、 Monte Carlo stochastic simulation method )(2079 read )
- Python The string is centered (1450 read )
- practice : Even sum 、 Threshold segmentation and subtraction ( list Two basic questions of the object )(1638 read )
- use pandas Solve a small problem (1964 read )
- Iteratable object and four functions (1065 read )
- “ Happy number ” Judge (1226 read )
- Roman digital converter ( Construct element module )(1932 read )
- Hot: Rome digital ( converter | Luo )(3536 read )
- Hot: Give Way QQ Group nickname color change code (26207 read )
- Hot: Fibonacci sequence ( recursive | for )(4037 read )
- The largest rectangle in the histogram (1646 read )
- Repeat start and end of sorting array elements (1236 read )
- Telephone dialing keyboard letter combination (1341 read )
- Password strength detector (1789 read )
- Find the balance point of the list (1812 read )
- Hot: String statistics (4280 read )
- Hot: Nim game ( Smart version starts )(3413 read ) Nim game ( Optimized version )(978 read )
Recommended conditions Click to read a thousand

Excellent articles :
- A good writer recommends :《python Complete self study course 》 Qi Wei manuscript free Serial
- OPP The three major characteristics : In the package property
- Understand through built-in objects python'
- Regular expressions
- python in “*” The role of
- Python A complete self-study manual
- Walrus operators
- Python Medium `!=` And `is not` Different
- The right way to learn programming
source : Laoqi classroom
Python Getting started 【Python 3.6.3】
A good writer recommends :
High quality creators in the whole stack field —— Cold guy ( Or a domestic college student ) Good writing :《 Non technical paper — About English and how to ask questions correctly 》,“ English ” and “ I will ask questions ” Are two sharp tools for learning .
CSDN Practical skills blog :
- 8 A good one Python Practical skills
- python Ignore the warning
- Python Code specification
- Python Of docstring standard ( Describe the standard writing of the document )
边栏推荐
- Yunna | fixed assets system management, NC system management where are the fixed assets
- 解决choice金融终端Excel/Wps插件修复visual basic异常
- 手写C语言之函数的嵌套调用和链式访问
- Video to image -cv2 Videocapture() usage
- Modbus TCP RTU protocol chart
- 出门在外保护好自己
- 科创人·味多美CIO胡博:数字化是不流血的革命,正确答案藏在业务的田间地头
- 月薪没到30K的程序员必须要背的面试八股,我先啃为敬!
- [cloud native] kernel security in container scenario
- Antd - tree structure: default deployment node attribute failure - Basic promotion
猜你喜欢
随机推荐
Mysql Duplicate entry ‘xxx‘ for key ‘xxx‘
网易云音乐内测音乐社交 App“MUS”,通过音乐匹配同频朋友
初始I/O及其基本操作
[garment software] what are the criteria for the selection of garment production management system?
【Spark】scala基础操作(持续更新)
A Si's mood swings
简单的页面
MySQL foundation 2
[spark] basic Scala operations (continuous update)
Initial i/o and its basic operations
岁月不饶人
VIM plug in manager VIM plug installation method
Too voluminous ~ eight part essay, the strongest king of interview!
Which direction of network development is better? Data communication engineer learning path sharing
太卷了~ 八股文,面试最强王者!
炒股开户选择哪家证券公司比较好哪家平台更安全
Outsourcing work for three years, waste a step confused
leetcode-1. Sum of two numbers
HDCP Paring
A Yu's Rainbow Bridge








