我是python的新手,有一个问题,要求根据用户输入的值输出"@"一定次数。但是,它也要求在两条不同的行上执行两次。
我知道我需要利用循环来输出"@"字符。
num = int(input())
counter = 0
while counter != num:
print("@", end='')
counter = counter + 1
在 num = 3 的情况下,我收到的输出是@@@
但是,它应该是
@@@
@@@
这看起来是一个棘手的问题。您走在正确的道路上,需要循环,但您需要循环所需的次数,例如
NUMBER_OF_LINES = 2
num = int(input())
# Loop the required number of lines
for _ in range(NUMBER_OF_LINES):
# Print the number of "@" symbols. Multiplying a string duplicates it.
print("@" * num)
这将产生所需的结果。
这是你想要的吗:
num = int(input())
num_of_lines = 2
for i in range(num_of_lines):
counter = 0
while counter != num:
print("@", end='')
counter = counter + 1
print()