Python中的ASCII艺术

Bea*_*ver 16 python ascii

我对python很陌生,把它当作一种爱好兴趣,并通过一些搜索发现自己是一堆来自" 计算实践 " 的练习,其中一个要求写一个ASCII数字,如下所示.

ascii十字架

这一切似乎都是一个足够简单的练习,但我似乎无法用一个数字来描绘这个,练习说明上面的绘图是通过使用数字"1"绘制的.

它还指出,不能或不应使用0或100以上的数字来创建ASCII绘图.

这是另一个例子:

这里的输入是数字"2".

更大的ascii十字架

我找到了一种方法来显示第一个图像,但不是通过任何方式使用给定的数字,只是在while循环中的一个简单的"else",所以我可以过滤掉低于或等于0的数字并且高于或等于100.

我已经死了.

我的代码如上所述,不使用变量编号来创建第一个图:

while True:
s = input("Give me a number to make a drawing with that is between 0 and 100: ")


if not s.isdigit():
    print ("Error, only numbers will make this program run.")
    continue #Try Again but with a number this time

if int(s) >= 100:
    print ("The number is bigger than or equal to 100 and won't work. \nDo try again.")
    continue #try again

if int(s) <= 0:
    print ("The number is smaller than or equal to 0 and won't work. \nDo try again.")
    continue #try again

else:
    print ("%5s" %("*" *3),"\n"'%5s' %("* *"),"\n" '%7s' %("*** ***"),"\n" '%7s' %("*     *"),"\n" '%7s' %("*** ***"),"\n" '%5s' %("* *"),"\n" '%5s' %("*" *3))


    print ('Want to make another drawing ?')
    continue #make another drawing
Run Code Online (Sandbox Code Playgroud)

该练习陈述如下:

大小$ n $的ASCII图由一行或多行组成.在每一行上只允许空格和星号(*),在一行上的每个星号之后不允许有空格,因此你应该以"\n"或换行符结束.然后是上述例子.

我的新代码示例依赖于变量输入: 此外,在此代码示例中,它设置为在输入为1时触发,当我增加输入数字时,我仍然遇到"放大"整个绘图的问题.

    while True:

 A = input("Give me a number to make a drawing with that is between 0 and 100: ")
 b = "***"
 c = "*"
 d = " "


 if not A.isdigit():
        print ("Error, only numbers will make this program run.")
        continue #Try Again but with a number this time

 if int(A) >= 100:
        print ("The number is bigger than or equal to 100 and won't work. \nDo try again.")
        continue #try again

 if int(A) <= 0:
        print ("The number is smaller than or equal to 0 and won't work. \nDo try again.")
        continue #try again


 else :
  range(1,99)
 if int(A) == (1) :
  print ((d *((int(A))*2)) + b,)
  print ((d *((int(A))*2))+ c + d + c,)
  print ((d *((int(A))*0))+ b + d + b,)
  print ((d *((int(A))*0))+ c + d*5 + c,)
  print ((d *((int(A))*0))+ b + d + b,)
  print ((d *((int(A))*2))+ c + d + c,)
  print ((d *((int(A))*2)) + b,)

  continue #try again
Run Code Online (Sandbox Code Playgroud)

但是我仍然得到了一个探索器,其中"增长"了ASCII数字内部的空间数量,同时增加了1比2.

因为我对第3行也有问题,因为它需要沿着控制台的两侧表示,它应该与侧面的间距为0,但它必须增加到2的间距与数字2 .

jmh*_*jmh 14

考虑1和2之间的区别.尝试手动绘制3和4应该是什么样子来使序列工作.把它想象成一个问题,你会得到一个序列的开始,你必须完成其余的工作.

喜欢:

0 1 1 2 3 5 8 13

如果你没有意识到这一点,那就是Fibonacci序列.一旦找出模式,就可以编写任意长的值序列.

想想这个简单的ascii序列:

1)

#
Run Code Online (Sandbox Code Playgroud)

2)

##
#
Run Code Online (Sandbox Code Playgroud)

3)

###
##
#
Run Code Online (Sandbox Code Playgroud)

4)看起来像什么?

或者另一个ascii序列:

1)

#
Run Code Online (Sandbox Code Playgroud)

2)

 #
# #
 #
Run Code Online (Sandbox Code Playgroud)

3)

  #
 # #
#   #
 # #
  #
Run Code Online (Sandbox Code Playgroud)

什么是(4)?

如果它仍然没有意义,尝试设计一些自己的递归形状,这些形状与你想要弄清楚的形状有点类似(也许是我的第二个例子中的某些内容).不要担心现在如何编码,只是担心输出应该是什么.然后看看模式并提出一个算法.