Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用x'制作图片;基于用户输入的多行中的s和空格_Python_Python 3.x - Fatal编程技术网

Python 使用x'制作图片;基于用户输入的多行中的s和空格

Python 使用x'制作图片;基于用户输入的多行中的s和空格,python,python-3.x,Python,Python 3.x,我正在为计算机编程做一些家庭作业(英国八年级)。以下是该计划的标准: 编写一个包含两个数字的函数。 第一个数字表示应显示的空格数,第二个数字表示应显示的X数。它们应显示在同一行上。 现在编写另一个函数,对第一个函数进行多次调用,并用Xs绘制一幅图。 我的代码如下: number_of_spaces=int(input("How many spaces?")) how_many_xs=int(input("How may x's")) how_many_lines=int(input("How m

我正在为计算机编程做一些家庭作业(英国八年级)。以下是该计划的标准: 编写一个包含两个数字的函数。 第一个数字表示应显示的空格数,第二个数字表示应显示的X数。它们应显示在同一行上。 现在编写另一个函数,对第一个函数进行多次调用,并用Xs绘制一幅图。 我的代码如下:

number_of_spaces=int(input("How many spaces?"))
how_many_xs=int(input("How may x's"))
how_many_lines=int(input("How many lines of this?"))
def one_line(x,y):
    print(' '*x,'x'*y)
one_line(number_of_spaces,how_many_xs)
def picture(x,y,z):
    print((one_line(number_of_spaces,how_many_xs))*z)
picture(number_of_spaces,how_many_xs,how_many_lines)
以下是python将所有三个变量的值都设置为5的结果:

有多少空格?5
x's5怎么样
这个有多少行
xxxxx
xxxxx
回溯(最近一次呼叫最后一次):
文件“C:\Python34\task 24.py”,第9行,在
图片(空格数、X数、行数)
文件“C:\Python34\task 24.py”,第8行,在图片中
打印((一行(空格数,空格数))*z)
TypeError:不支持*:“NoneType”和“int”的操作数类型
我尝试将变量“how_many_lines”的格式更改为float,但得到了类似的错误消息,只是它说不支持
NoneType
float
。对于变量“多少行”的格式
str
,我得到错误消息:

TypeError:无法将序列与类型为'NoneType'的非int相乘。

如果您能提供任何帮助并帮助我避免在将来遇到这种情况,我们将不胜感激。

您的
one_line()
函数没有显式返回任何内容,因此它实际上返回
None
(类型为
NoneValue

尝试按如下所示进行更改:

def one_line(x, y):
#    print(' '*x, 'x'*y)
    return ' '*x, 'x'*y

我不确定最终结果是否可以用图片来描述,但这似乎与您所描述的相符。 前面的答案基本上是给出字符列表,而不是将其打印为文本“艺术”


one_line
不应打印,而是返回
'*x,'x'*y
我也会尝试一下,如果它有效或无效,我会回复。谢谢你,事实上这个效果更好。
number_of_spaces=int(input("How many spaces?"))
how_many_xs=int(input("How may x's"))
how_many_lines=int(input("How many lines of this?"))


def one_line(x,y):
    print(' '*x,'x'*y)
    return ""


def picture(number_of_spaces, how_many_xs, how_many_lines):
    for i in range(0,how_many_lines):
        print(' ' * number_of_spaces, 'x' * how_many_xs)


picture(number_of_spaces, how_many_xs, how_many_lines)