Quadrilateral V2 - Python Programming Exercise

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 dimensions using the number as the inner symbol. The program will use the for loop to print the number in a pattern that represents the rectangle. The width determines the number of characters in each row, while the height dictates the number of rows. This task will help you practice using loops for text manipulation and constructing simple shapes with text output in Python. By completing this exercise, you will improve your understanding of user input handling in Python, and how to control the flow of a program using loops. This skill is essential for developing more advanced applications, especially when working with dynamic user data and generating visual outputs in a text-based format. Understanding how to combine user input with loops and conditional statements will make you more proficient in building interactive Python programs.

 Category

Mastering Flow Control

 Exercise

Quadrilateral V2

 Objective

Develop a Python program that prompts the user for a number, width, and height, and displays a rectangle of that width and height using that number for the inner symbol, as shown in the example below:

Enter a number: 4
Enter the desired width: 3
Enter the desired height: 5

444
444
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: "))

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

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

 Output

Enter a number: 4
Enter the desired width: 3
Enter the desired height: 5
444
444
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.

  •  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...

  •  Absolute Magnitude

    This Python program calculates and displays the absolute value of a number x. The absolute value of a number is defined as the number itself if it is positive,...

  •  Empty Rectangle

    This Python program prompts the user for a symbol, width, and height, and then displays a hollow rectangle using that symbol for the outer border...