parent
24048b2e1b
commit
b3875c6583
|
@ -407,19 +407,26 @@ import os
|
|||
import time
|
||||
|
||||
|
||||
# 展示跑马灯效果,请在cmd中运行效果更好
|
||||
def main():
|
||||
content = '北京欢迎你为你开天辟地…………'
|
||||
color_nums = [41, 42, 43, 44, 45, 46, 47, 48]
|
||||
|
||||
while True:
|
||||
content = content[1:] + content[0]
|
||||
color_num = color_nums.pop(0)
|
||||
process = f"\033[1;30;{color_num}m{content}\033[0m"
|
||||
# 清理屏幕上的输出
|
||||
os.system('cls') # os.system('clear')
|
||||
print(content)
|
||||
print(process)
|
||||
# 休眠200毫秒
|
||||
time.sleep(0.2)
|
||||
content = content[1:] + content[0]
|
||||
color_nums.append(color_num)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
```
|
||||
|
||||
#### 练习2:设计一个函数产生指定长度的验证码,验证码由大小写字母和数字构成。
|
||||
|
@ -528,6 +535,21 @@ def main():
|
|||
if __name__ == '__main__':
|
||||
main()
|
||||
```
|
||||
优化计算指定的年月日
|
||||
```
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
# 计算指定的年月日是这一年的第几天
|
||||
def which_day(year, month, day):
|
||||
the_day = datetime(year, month, day)
|
||||
first_day = datetime(year, 1, 1)
|
||||
return (the_day-first_day).days
|
||||
|
||||
|
||||
print(which_day(1989, 10, 22))
|
||||
print(which_day(1988, 10, 22))
|
||||
```
|
||||
|
||||
#### 练习6:打印[杨辉三角](https://zh.wikipedia.org/wiki/%E6%9D%A8%E8%BE%89%E4%B8%89%E8%A7%92%E5%BD%A2)。
|
||||
|
||||
|
@ -672,4 +694,4 @@ if __name__ == '__main__':
|
|||
main()
|
||||
```
|
||||
|
||||
>**说明:** 最后这个案例来自[《Python编程快速上手:让繁琐工作自动化》](https://item.jd.com/11943853.html)一书(这本书对有编程基础想迅速使用Python将日常工作自动化的人来说还是不错的选择),对代码做了一点点的调整。
|
||||
>**说明:** 最后这个案例来自[《Python编程快速上手:让繁琐工作自动化》](https://item.jd.com/11943853.html)一书(这本书对有编程基础想迅速使用Python将日常工作自动化的人来说还是不错的选择),对代码做了一点点的调整。
|
||||
|
|
Loading…
Reference in New Issue