Data Presentation Styles - Python Programming Exercise

In this exercise, you will 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 will complete this task twice: first using print() and then using string formatting. This exercise helps you practice handling user input, using print statements, and exploring string formatting in Python. By completing this exercise, you will strengthen your understanding of Python syntax and become more comfortable with displaying user input in different formats. It will also introduce you to different ways of formatting output, such as using print() and string formatting methods. These skills are essential for creating dynamic Python programs that respond to user input and present information clearly and effectively.

 Category

Your First Steps in Python

 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

 Copy 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

 More Python Programming Exercises of Your First Steps in Python

Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.

  •  Quadrilateral Dimensions

    In this exercise, you will develop a Python program to prompt the user for a number and then display a rectangle 3 columns wide and 5 rows tall using that d...

  •  Conversion

    In this exercise, you will develop a Python program that asks the user for a temperature in Celsius and converts it to both Kelvin and Fahrenheit...

  •  Initial interaction with Python

    In this exercise, you will develop a Python program to output "Hello" on the screen, followed by your name on a separate line. This exercise is perfect for pra...

  •  Addition of two values

    In this exercise, you will develop a Python program to print the result of adding 12 and 13 on the screen. This exercise is perfect for practicing basic arithm...

  •  Divide two values

    In this exercise, you will develop a Python program to display the result of dividing 24 by 5 on the screen. This exercise is perfect for practicing basic arit...

  •  Complex Calculations and Order of Operations

    In this exercise, you will develop a Python program to calculate and display the results of several mathematical operations. You will work with expressions such as 1 + 3 ...