Answer to Question #159573 in Python for Meera

Question #159573

#(a) Ask the user for their name and output the name 5 times.

#Extension:

#(b) Allow the user to specify the number of outputs. (1T, 1K)


1
Expert's answer
2021-01-29T01:12:06-0500
#a
# Python 3 program to prompt user his/her name and print it 5 times
# Variable to hold name
name = input("Enter your name: ")

# Use for loop to print it 5 times
for x in range(5):
    print(name)  # Display name



#b Extension
# Python 3 program to prompt user his/her name and number of times to print name
# Variable to hold name
name = input("Enter your name: ")

# Prompt number of times to print the name and cast the input to integer type
number = int(input("Enter the number of times to print the name: "))

# Use for loop to print it depending on the number of times entered
for x in range(number):
    print(name)  # Display name





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS