Take Base b And Height h as an Input And Write a Program to Print a Parallelogram in Python

Hi in this article you will learn about a Python program to print the parallelogram using stars,  given the base and height  as input to the Python program so your task should be to print the parallelogram on standard output.

I will be trying to solve this using only four lines of code.

 

 

Take Base b And Height h as an Input And Write a Program to Print a Parallelogram in Python

 

 



Take Base b And Height h as an Input And Write a Program to Print a Parallelogram in Python

Take variables base and height i.e, b and h  and ask a user to enter the base and height of the parallelogram using the input function call and then convert it into an integer.

b = int(input("Enter Base of Parallelogram : "))
h = int(input("Enter Height of Parallelogram : "))







Use the for loop to iterate  from 0 to parallelogram height  by using the range function and get the index.   inside the following use print statement to print the  space multiplied by index and star multiply by the base.

Just keep printing the space and stars multiplied by the index and parallelogram base as shown below

for index in range(h):
   print(" " * index + "* " * b)






Python complete program
===========================

b = int(input("Enter Base of Parallelogram : "))
h = int(input("Enter Height of Parallelogram : "))

for index in range(h):
print(" " * index + "* " * b)





Output 1
==================

Enter Base of Parallelogram : 7
Enter Height of Parallelogram : 4
* * * * * * *
 * * * * * * *
  * * * * * * *
   * * * * * * *




Output 2
==================

Enter Base of Parallelogram : 12
Enter Height of Parallelogram : 8
* * * * * * * * * * * *
 * * * * * * * * * * * *
  * * * * * * * * * * * *
   * * * * * * * * * * * *
    * * * * * * * * * * * *
     * * * * * * * * * * * *
      * * * * * * * * * * * *
       * * * * * * * * * * * *




Output 3
=================

Enter Base of Parallelogram : 5
Enter Height of Parallelogram : 3
* * * * *
 * * * * *
  * * * * *




Conclusion
===============

Execute the above Python program by providing the random base and height values of a parallelogram and note down the results

Comment it down below if you have any query is related to above Python program



Post a Comment

0 Comments