[英]How do I make a rectangle with user input?
I need to make a square with 2 pieces of user input: n
and m
. 我需要用2个用户输入组成一个正方形:
n
和m
。 The rectangle has to be n * m
and made out of "*"
. 矩形必须为
n * m
并由"*"
。 I can make the square if I say for example n = (5)
and m = (7)
, when I add make m
and n
user input it prints n
instead of a rectangle made of "*"
... This is what I have so far, what am I doing wrong? 如果我说例如
n = (5)
和m = (7)
,我可以制作正方形,当我添加make m
和n
用户输入时,它会打印n
而不是由"*"
制成的矩形...这就是我的意思到目前为止,我在做什么错?
n = int(input(3))
m = int(input(4))
for i in range(n):
print ('*' * m)
The expected output is: 预期的输出是:
****
****
****
Edit: Ok, I think my problem is that I don't know how to correctly enter input, can anyone help me on that? 编辑:好的,我想我的问题是我不知道如何正确输入输入,有人可以帮我吗? Second Edit: Alright, thanks everybody for helping!
第二编辑:好,谢谢大家的帮助! I found out how it works, I didn't enter actual input after running the program.
我发现它是如何工作的,运行该程序后没有输入实际的输入。 Thanks again!
再次感谢!
This creates a rectangle. 这将创建一个矩形。
n = int(input("First number "))
m = int(input("Second number "))
star = "*"
for i in range(n):
print(star*m)
Example: 例:
First number 4
Second number 8
********
********
********
********
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.