146k views
22 votes
Programming Exercise:

1- Write a program that asks the user to enter a
word and then prints that word 25 times (each on
separate lines)

User Beyonce
by
4.6k points

1 Answer

7 votes

Method 1:

word = input("> ")

for _ in range(25):

print(word)

Assigning the variable "word" to the function input() (Which retreves what the user types). Then using a for loop which repeats 25 times. And each time print the word. The print() function automatically creates a new line.

Method 2:

print(f"{input('> ')}\\"*25)

This code does the exact same thing as previously but only calls the print() function once and instead creates a string which is 25 lines long and has the users' input on each line. It's cool to write it on a single line, however, not very pedagogcall and pretty messy.

User Ecarlin
by
5.1k points