linux终端输出彩色字体

来源:互联网 发布:苹果手机数据恢复方法 编辑:程序博客网 时间:2024/04/29 10:30

控制码如下:


编写python程序:

song@ubuntu:~$ vi ex3.py
song@ubuntu:~$ more ex3.py
#!/usr/bin/env python
#_*_ coding:utf-8 _*_
real_age=28
for i in range(3):
    age=input('Please input the age:')
    if age>real_age:
        print '\033[31;1mtoo big,please think smaller!\033[0m'
    elif age<real_age:
        print '\033[42;1mtoo small,please think bigger!\033[0m'
    else:
        print '\033[33;1mGood,you guess right!!!\033[0m'
        break
    print 'you have still %s shots' % (2-i)


song@ubuntu:~$ 

运行结果,如下图:


(完)

1 0
原创粉丝点击