社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

我在python上写了一个简单的代码,但它没有达到预期的效果。有人能帮我吗

J0J0 • 4 年前 • 1469 次点击  

此代码将显示一个图像,其中0将是“”,1将是“*”。这将显示一个图像:

   picture = [
       [0,0,0,1,0,0,0 ],
       [0,0,1,1,1,0,0 ],
       [0,1,1,1,1,1,0 ],
       [1,1,1,1,1,1,1 ],
       [0,0,0,1,0,0,0 ],
       [0,0,0,1,0,0,0 ]
        ]

要展示的图像应该是:

   *   
  ***  
 ***** 
*******
   *   
   *

我需要有人帮助我的代码:

   picture = [
       [0,0,0,1,0,0,0 ],
       [0,0,1,1,1,0,0 ],
       [0,1,1,1,1,1,0 ],
       [1,1,1,1,1,1,1 ],
       [0,0,0,1,0,0,0 ],
       [0,0,0,1,0,0,0 ]
        ]
 row=0
 col=0
 picture[row][col]

 while row<=5:

 while col<=6:
  if picture[row][col]== False:
    picture[row][col]=" "
    col=1+col
  else:
    picture[row][col]="*"
    col=col+1

  print(
    str(picture[row][0]) +" "+ str(picture[row][1]) +" "+ 
  str(picture[row][2])+" "+str(picture[row][3])+" "+str(picture[row][4])
    +" "+str(picture[row][5])+" "+str(picture[row][6])
          )
 row=row+1

我的代码产生了什么:

  0 0 1 0 0 0
    0 1 0 0 0
      1 0 0 0
      * 0 0 0
      *   0 0
      *     0
      *
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/130946
文章 [ 3 ]  |  最新文章 4 年前