Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

WORKSHEET 1.1

Student Name: Ankit Vashisth UID: 22BCS13378


Branch: CSE Section/Group: 707-A
Semester: 4th Date of Performance: 08/02/2024
Subject Name: Python Subject Code: 22CSH-259

1. Aim: Write a program that takes string as input from user and prints out number
of vowels, consonants, digits and symbols and characters in that string. Use
datatypes, control statements and func<on to implement this.

2. Source Code:

def count(s):
vowels = 0
consonants = 0
digits = 0
symbols = 0

for ch in s:
if ch.islower() and ch in 'aeiou':
vowels += 1
elif ch.isalpha():
consonants += 1
elif ch.isdigit():
digits += 1
COMPUTER SCIENCE & ENGINEERING

else:
symbols += 1

print(f"Number of vowels: {vowels}")


print(f"Number of consonants: {consonants}")
print(f"Number of digits: {digits}")
print(f"Number of symbols: {symbols}")

s = input("Enter a string: ")


count(s)

3. Screenshot of Outputs:

4. Learning Outcomes:

• Dictionary Handling
• List Manipulation
• Iteration and Looping
• User Input Handling
• Functions

You might also like