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

yipeiwu_com6年前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程序设计有所帮助。

相关文章

pycharm运行程序时在Python console窗口中运行的方法

pycharm运行程序时在Python console窗口中运行的方法

问题:在pycharm中点击run运行程序,发现没有打开run窗口,而是打开的Python console窗口。 解决方法:打开菜单栏run->edit configuration...

python/Matplotlib绘制复变函数图像教程

python/Matplotlib绘制复变函数图像教程

今天发现sympy依赖的库mpmath里也有很多数学函数,其中也有在复平面绘制二维图的函数cplot,具体例子如下 from mpmath import * def f1(z):...

python复制文件的方法实例详解

本文实例讲述了python复制文件的方法。分享给大家供大家参考。具体分析如下: 这里涉及Python复制文件在实际操作方案中的实际应用以及Python复制文件 的相关代码说明,希望你会有...

python实现在一个画布上画多个子图

python实现在一个画布上画多个子图

matplotlib 是可以组合许多的小图, 放在一张大图里面显示的. 使用到的方法叫作 subplot. 均匀画图 使用import导入matplotlib.pyplot模块, 并简写...

pytorch使用指定GPU训练的实例

本文适合多GPU的机器,并且每个用户需要单独使用GPU训练。 虽然pytorch提供了指定gpu的几种方式,但是使用不当的话会遇到out of memory的问题,主要是因为pytorc...