- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我是 python 的新手,把它作为一种兴趣爱好,通过一些搜索,我自己找到了一堆来自“计算实践”的练习,其中一个是关于写作的一个 ASCII 数字,如下所示。
这似乎是一个足够简单的练习,但我似乎无法理解使用数字来绘制它,练习表明上面的绘图是通过使用数字“1”绘制的。
它还声明不能或不应该使用小于 0 或大于 100 的数字来创建 ASCII 绘图。
还有一个例子:
这里输入的是数字“2”。
我找到了一种让第一张图片出现的方法,但不是通过以任何方式使用给定的数字,只是在 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/
无论是谁读到这篇文章,我都感谢您花时间阅读。 本质上,我试图通过调用 x 个方法来生成这个精确的 ASCII 艺术,我个人考虑了 3 个: * * ** ** ***
这太琐碎了,听起来很傻,但请多多包涵。 我以前会画ASCII艺术笑脸similar to this post通过做类似的事情: Console.Write((char)1); 当我在 Windows
这样的图像转换算法是如何工作的? 我想将位图转换为 ASCII 艺术。谁能帮我看看我应该使用哪种算法? . W ,
我正在尝试为 android 制作游戏。我目前已将所有美术资源加载到 drawables 文件夹中,但我的问题是如何实际引用特定资源来渲染它? 我知道每个文件都有一个唯一的@id,我可能必须在onDr
我试图垂直反射(reflect)这门艺术。 示例: 但这是我最终得到的: 代码如下: String reverse; for(int i=1;i=0;j--) // probably the wors
我正在尝试使用 JavaScript 函数在我的网站上获取一些 ASCII 艺术作品,但结果并不是我现在想要的...... 它应该是这样的: 这是我用来尝试实现该目标的代码: function log
我正在尝试创建一个脚本,该脚本将接受用户输入(仅字母)并向用户输出 ASCII 艺术。两种输出方法是水平或垂直。我遇到的问题是如何水平打印字典值。 这是我到目前为止所拥有的: def convert(
下面的代码(用 patorjk.com Text to ASCII Art Generator 生成)给出了预期的结果(“TEST”ASCII 艺术文本): Windows:Firefox、Chrom
我正在尝试像这样打印 ascii 艺术: print(("""\ ._ o o
所以..这是(无论如何对我来说)这个程序最重要的功能。我需要这个才能工作。请不要笑..(好吧你可以笑)但是当我的程序出错时,我希望它显示这个: _ _,---._ ,
我正在尝试输入 ASCII art在 C++ 程序中,并通过手动打印每一行来实现,但结果与 ASCII 艺术完全不同。就像: 出现这种情况是因为提示无法识别字符还是我没有正确操作? 这是我正在尝试做的
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 11 年前。 Improve thi
我有一个很长的多行 ascii 艺术字符串,我想使用 Python curses 模块将其呈现给用户。我对此有点困惑,因为在 curses 中打印字符串的唯一方法是 addstr(y,x,string
目前我正在尝试读取可能包含 ASCII 艺术的 .txt 文件并使用 JQuery 在我的 HTML 文档中显示它们。简单的文本显示正确,但我有艺术格式问题。 我该如何解决这个问题? $(docume
我正在用 optparse 模块制作一个 shell 脚本,只是为了好玩,所以我想打印一个漂亮的 ascii 图来代替描述。 原来这段代码: parser = optparse.OptionParse
我是 python 的新手,把它作为一种兴趣爱好,通过一些搜索,我自己找到了一堆来自“计算实践”的练习,其中一个是关于写作的一个 ASCII 数字,如下所示。 这似乎是一个足够简单的练习,但我似乎无法
这个问题在这里已经有了答案: Render a string in HTML and preserve spaces and linebreaks (7 个答案) 关闭 9 个月前。 我该怎么做才能
我曾经为一项工作做过编程测试,其中涉及用 C# 制作 ASCii 艺术。我在这方面做得并不好,因为我对在 C#(或任何编程知识)中这样做的想法或经验知之甚少。 .NET 中是否有任何值得了解/练习的资
我正在编写一个小程序,想知道是否有办法在 R 中包含 ASCII 艺术。我在 python 中寻找等效的三个引号( """ 或 ''' )。 我尝试使用 cat或 print没有成功。 最佳答案 不幸
因此,对于我的 Java 入门类(class),我想用 ASCII 创建一个 Gingerbread 人。这是第一个作业,所以到目前为止,该类(class)仅涵盖了 println 语句。我在 OSX
我是一名优秀的程序员,十分优秀!