-2

How can I read an integer (integer) from the user, and read a phrase (phrase) from the user. Then print the phrase (integer) times, each time on a different line?

This is what I have so far:

integer = int(input("Please enter an integer: "))
phrase = str(input("Please enter a phrase: "))
ans = integer * phrase
print(ans)

This only prints the phrase however many times on a single line, how can I separate prints "hellow" in different lines rather instead of "hello,hello,hello"

0

1 Answer 1

1

you probably want something like:

integer = int(input("Please enter an integer: "))
phrase = str(input("Please enter a phrase: "))
for _ in range(integer):
    print(phrase)

I use _ here to denote a throwaway variable because you're not actually using it anywhere, you're just iterating integer times.

You could also just append a newline character to your phrase and call print a single time like this:

ans = (phrase + '\n') * integer
print(ans)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.