langstonw
langstonw

Reputation: 1

How to continue a loop on a new line?

I'm new to python and have a problem that asks to output "@"a certain number of times based upon the value that the user entered. However it also asks to do it twice on two different lines.

I understand that I need to utilize a loop to output the "@" character.

num = int(input())
counter = 0
while counter != num:
    print("@", end='')
    counter = counter + 1

In the case of num = 3, the output I receive is @@@ however, it is supposed to be

@@@  
@@@

Upvotes: 0

Views: 144

Answers (2)

Tim
Tim

Reputation: 2637

This looks like a bit of a trick question. You are on the right path requiring a loop but you need to loop the required number of times eg

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)

That will produce the required results.

Upvotes: 1

Scott
Scott

Reputation: 5858

Is this what you want:

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()

Upvotes: 0

Related Questions