Python Homework - Match Case and For Loop
1. Create a menu using match-case where a user can choose:
# 1: Say Hello
# 2: Print a Joke
# 3: Show Today's Date
import datetime
choice = int(input("Choose an option:\n1: Say Hello\n2: Print a Joke\n3: Show
Today's Date\nEnter your choice: "))
match choice:
case 1:
print("Hello! Hope you're having a great day!")
case 2:
print("Why don't scientists trust atoms? Because they make up
everything!")
case 3:
print("Today's date is:", datetime.date.today())
case _:
print("Invalid option.")
2. Count how many vowels are in a user-entered string.
text = input("Enter a string: ")
vowels = "aeiouAEIOU"
count = 0
for char in text:
if char in vowels:
count += 1
print("Number of vowels:", count)
3. Create a star pattern triangle using nested for loops.
rows = 5
Python Homework - Match Case and For Loop
for i in range(1, rows + 1):
print("*" * i)