gpt4 book ai didi

python - Python 中的 ASCII 艺术

转载 作者:太空狗 更新时间:2023-10-29 16:55:56 27 4
gpt4 key购买 nike

我是 python 的新手,把它作为一种兴趣爱好,通过一些搜索,我自己找到了一堆来自“计算实践”的练习,其中一个是关于写作的一个 ASCII 数字,如下所示。

ascii cross

这似乎是一个足够简单的练习,但我似乎无法理解使用数字来绘制它,练习表明上面的绘图是通过使用数字“1”绘制的。

它还声明不能或不应该使用小于 0 或大于 100 的数字来创建 ASCII 绘图。

还有一个例子:

这里输入的是数字“2”。

bigger ascii cross

我找到了一种让第一张图片出现的方法,但不是通过以任何方式使用给定的数字,只是在 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

练习说明如下:

大小为$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

但随着 1 到 2 的增加,ASCII 数字中的空格数“增加”,我仍然遇到了问题。

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

最佳答案

想一想 1 和 2 之间的区别。尝试用手画出 3 和 4 应该是什么样子以使序列有效。把它想象成这样的问题之一,给定一个序列的开始,你必须解决剩下的问题。

喜欢:

0 1 1 2 3 5 8 13

如果您没有马上认出它,那就是斐波那契数列。弄清楚模式后,您可以编写任意长的值序列。

想想这个简单的 ascii 序列:

1)

#

2)

##
#

3)

###
##
#

4) 是什么样子的?

或者另一个ascii序列:

1)

#

2)

 #
# #
#

3)

  #
# #
# #
# #
#

什么是 (4)?

如果它仍然没有意义,请尝试设计一些您自己的递归形状,这些形状与您试图找出的形状有点相似(可能与我的第二个示例类似)。现在不要担心如何编码,只需担心输出应该是什么。然后查看模式并得出算法。

关于python - Python 中的 ASCII 艺术,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13076194/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com