Exercise
Data Presentation Styles
Objective
Develop a Python program to prompt the user for a number and display it four times in a row, separated by spaces, and then four times in the next row without any spaces. You must do it twice: first using print() and then using string formatting.
Example:
Enter a number: 3
3 3 3 3
3333
3 3 3 3
3333
Example Python Exercise
Show Python Code
# Prompt the user to enter a number
num = input("Enter a number: ")
# Display the number four times in a row, separated by spaces, using print()
print(num, num, num, num)
# Display the number four times in a row, without spaces, using print()
print(num * 4)
# Display the number four times in a row, separated by spaces, using string formatting
print(f"{num} {num} {num} {num}")
# Display the number four times in a row, without spaces, using string formatting
print(f"{num * 4}")
Output
Enter a number: 3
3 3 3 3
3333
3 3 3 3
3333
Share this Python Exercise