Quadrilateral - Python Programming Exercise

In this exercise, you will develop a Python program that prompts the user to enter a number and a width, and then displays a square of that width using the entered number as the inner symbol. The program will repeat the number for the specified width, creating a visual representation of a square. This task will help you practice managing user input and working with loops to generate patterns in Python. By completing this exercise, you will improve your skills in handling user input and using loops to generate repeating characters or patterns. This is an essential skill in programming that can be applied in various contexts, such as creating ASCII art, formatting output, and designing dynamic user interfaces.

 Category

Mastering Flow Control

 Exercise

Quadrilateral

 Objective

Develop a Python program that prompts the user to enter a number and a width, and displays a square of that width using that number for the inner symbol, as shown in this example:

Enter a number: 4
Enter the desired width: 3

444
444
444

 Example Python Exercise

 Copy Python Code
# Prompt the user to enter a number
num = input("Enter a number: ")

# Prompt the user to enter the desired width
width = int(input("Enter the desired width: "))

# Use a while loop to display the square
i = 0
while i < width:
    print(num * width)
    i += 1

 Output

Enter a number: 4
Enter the desired width: 3
444
444
444

 Share this Python Exercise

 More Python Programming Exercises of Mastering Flow Control

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.

  •  Pause & Proceed

    In this exercise, you will develop a Python program that writes the even numbers from 10 to 20, both inclusive, except 16. The program will implement three different methods...

  •  Quadrilateral V2

    In this Python exercise, you will develop a program that prompts the user to input a number, width, and height and displays a rectangle of the specified...

  •  Iterative Patterns

    This Python program allows the user to input two numbers and displays all the numbers between them (inclusive) three times using different types of loops: "for"...

  •  Numerical Digits

    This Python program demonstrates how to calculate the number of digits in a positive integer by repeatedly dividing the number by 10. If the user enters a n...

  •  Empty Square

    This Python program prompts the user to input a symbol and a width, then displays a hollow square with the specified width. The square's outer border is...

  •  Output

    This Python program prompts the user for two integer numbers and calculates their product without using the "*" operator. Instead, it uses consecutiv...