### Exercise 4: Solution And First Solver

This tutorial contains the solution of Exercise-4 (Astrologer's Star). In Exercise-4, we had to create a program that could print some patterns of stars.

#### 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.
• The output should be like this:

``````*
**
***
****``````

#### Code file as described in the video

``````# Exercise 4
# Pattern Printing
# Input = Integer n
# Boolean = True or False
#
# True n=5
# *
# **
# ***
# ****
#
# False n=5
# ****
# ***
# **
# *
# print("Pattern printing")
# num = int(input("Enter num how many rows you want : "))
# print("Enter 1 or 0")
# bool_val = input("1 for True value or 0 for False : ")
# if bool_val=="1":
#     for i in range(0,num+1):
#         print("*"*i)
#
# if bool_val=="0":
#     for i in range(num,0,-1):
#         print("*"* i)

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)

``````

shellstar 8 months, 1 week ago
```how are you sir,
```
pushpak 4 months, 3 weeks ago
```#printing star pattern
i=1
get = int(input())
print("Enter a number\nfor True :1 \nfor False :0")
Bool = int(input())

if Bool==1:
while i<=get:
print("*"*i)
i = i + 1
continue
elif Bool==0:
while i<=get:
print("*"*get)
get=get - 1
continue
else:
print("sorry given wrong input")
```
lolnoob 4 months, 2 weeks ago
`Achha hai. Lekin last line me "sorry invalid input given" ki jagah try and except use karein. `

#### Resources

No downloadable resources for this video. If you think you need anything, please post it in the QnA!

#### Course Announcements

Any Course related announcements will be posted here