Python Exercise 5 --- "Astrologer's Stars"

 Python  Exercise 5 --- "Astrologer's Stars"

In today’s exercise, what we have to do is, we have to print a pattern similar to that of  a right-angle triangle, such as:

*
**
***
****

You have to follow certain instructions, which are as follows:

  • You have to take an integer type variable, and the input of the variable will define the length of the triangle.
  • You have to declare another Boolean variable.
  • When the value of Boolean is 1 i.e. True, the pattern will be printed as shown above.
  • But if the value of Boolean is 0 or false, then the triangle will be printed upside down.

Solution:

a = int(input("Enter the number of lines you want to print \n"))
b = bool(int(input("Enter 0 or 1 \n")))


def star(a, b):
if b == True:
c = 1
while c <= a:
print(c * "*")
c = c + 1
else:
while a > 0:
print(a * "*")
a = a - 1


star(a, b)

Comments

Popular posts from this blog

Python Exercise 7 --- "Snake, Water, Gun"

Python Tutorial 38 --- "Self & __init__() (Constructors)(OOPS 3)"

Python Exercise 4 --- "Number Guessing Game"