0% found this document useful (0 votes)
7 views2 pages

Python Homework Match ForLoop

The document outlines a Python homework assignment that includes three tasks: creating a menu with match-case for user options, counting vowels in a user-entered string, and generating a star pattern triangle using nested for loops. Each task is accompanied by example code snippets. The tasks aim to reinforce understanding of control structures and string manipulation in Python.

Uploaded by

Pankaj Navale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Python Homework Match ForLoop

The document outlines a Python homework assignment that includes three tasks: creating a menu with match-case for user options, counting vowels in a user-entered string, and generating a star pattern triangle using nested for loops. Each task is accompanied by example code snippets. The tasks aim to reinforce understanding of control structures and string manipulation in Python.

Uploaded by

Pankaj Navale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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)

You might also like