Python2实现的LED大数字显示效果示例

yipeiwu_com5年前Python基础

本文实例讲述了Python2实现的LED大数字显示效果。分享给大家供大家参考,具体如下:

#filename:bigNumber.py
zero=['*******','*   *','*   *','*   *','*   *','*   *','*******']
one=['   *','   *','   *','   *','   *','   *','   *']
two=['*******','   *','   *','*******','*   ','*   ','*******']
three=['*******','   *','   *','*******','   *','   *','*******']
four=['*   *','*   *','*   *','*******','   *','   *','   *']
five=['*******','*   ','*   ','*******','   *','   *','*******']
six=['*******','*   ','*   ','*******','*   *','*   *','*******']
seven=['*******','   *','   *','   *','   *','   *','   *']
eight=['*******','*   *','*   *','*******','*   *','*   *','*******']
nine=['*******','*   *','*   *','*******','   *','   *','*******']
numArr=[zero,one,two,three,four,five,six,seven,eight,nine]
while True:
  try:
    #input a number
    num = raw_input("Enter a number:")
    for i in range(0,7):
      line=''
      j=0
      while j<len(num):
        n=int(num[j])
        line+=numArr[n][i]+' '
        j+=1
      print line
  except ValueError as err:
    print err

运行效果如下图:

更多Python相关内容感兴趣的读者可查看本站专题:《Python列表(list)操作技巧总结》、《Python编码操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总

希望本文所述对大家Python程序设计有所帮助。

相关文章

深入浅出分析Python装饰器用法

本文实例讲述了Python装饰器用法。分享给大家供大家参考,具体如下: 用类作为装饰器 示例一 最初代码: class bol(object): def __init__(self...

pandas删除行删除列增加行增加列的实现

创建df: >>> df = pd.DataFrame(np.arange(16).reshape(4, 4), columns=list('ABCD'), ind...

python3 unicode列表转换为中文的实例

python3 unicode列表转换为中文的实例

查了很多很多的资料无果,果然知乎牛逼,完美解决。 爬取网站时,最终得到list内容,编码为unicode,想让其转换为汉字并输出。 需要提取的为下图中unicode部分: 保存为列表...

python万年历实现代码 含运行结果

python万年历实现代码 含运行结果

本文实例为大家分享了python实现万年历的具体代码,供大家参考,具体内容如下 #coding:utf-8 def leap_year(year):#判断平瑞年 if year...

Python 实现中值滤波、均值滤波的方法

Python 实现中值滤波、均值滤波的方法

红包: Lena椒盐噪声图片: # -*- coding: utf-8 -*- """ Created on Sat Oct 14 22:16:47 2017 @author:...