9. Astrologer's Star.py

# Pattern Printing
# input = Integer n
# Boolean = True or False

# True n=4
# *
# **
# ***
# ****

# n = no.of rows

# False n = 4
# ****
# ***
# **
# *


# print the stars according to the date of birth of the client



Raahu = input("Enter 'YES' if Raahu present else enter 'NO': ").lower()

# str(Raahu)
# Raahu = False
if Raahu == "yes":
# Take date input from the user
date_of_birth = input("Enter the Date Of Birth (DD-MM-YYYY): ")

# Extracting the date from the DOB
dob = date_of_birth.split('-')

# Custom exception class for invalid date format
class InvalidDateFormatError(Exception):
def __init__(self, message="Invalid date format. Please use DD-MM-YYYY."):
self.message = message
super().__init__(self.message)

# Raise an error if date is not in 3 part format i.e DD-MM-YYYY
# if len(dob) != 3:
# print("Enter a valid (DD-MM-YYYY) date format!")

# Storing the day in another variable to use it as no. of rows of the star pattern
date = dob[0]
# Typecasting of the day into int
day = int(date)

try:
# Check the date is valid or not
if day <= 31:
# i to iterate throughout the rows
for i in range(1, day + 1):
# j to iterate throughout the columns
for j in range(1, i + 1):
print("*", end=" ")
print()
else:
print("Invalid date entered!")

except InvalidDateFormatError as e:
print(f"Error: {e}", "Invalid date format. Please enter the date in DD-MM-YYYY format.")


elif Raahu == "no":

# Take date input from the user
date_of_birth = input("Enter the Date Of Birth (DD-MM-YYYY): ")
# Extracting the date from the DOB
dob = date_of_birth.split('-')


# Custom exception class for invalid date format
class InvalidDateFormatError(Exception):
def __init__(self, message="Invalid date format. Please use DD-MM-YYYY."):
self.message = message
super().__init__(self.message)

# Raise an error if date is not in 3 part format i.e DD-MM-YYYY
# if len(dob) != 3:
# print("Enter a valid (DD-MM-YYYY) date format!")
# Storing the day in another variable to use it as no. of rows of the star pattern
date = dob[0]
# Typecasting of the day into int
day = int(date)

try:
# Check the date is valid or not
if day <= 31:
# i to iterate throughout the rows
for i in range(day, -1, -1):
# j to iterate throughout the columns
for j in range(1, i + 1):
print("*", end=" ")
print()
else:
print("Invalid date entered!")



except InvalidDateFormatError as e:
print(f"Error: {e}", "Invalid date format. Please enter the date in DD-MM-YYYY format.")


else:

print("Wrong Choice Entered!!! ") 

Comments

Popular posts from this blog

3.FaulyCalculator.py

11.Snake Water Gun Game.py

15.PyStopWatch.py