0% found this document useful (0 votes)
10 views

Computer Science Python Programs

It will be veru helpful

Uploaded by

ak2712329
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)
10 views

Computer Science Python Programs

It will be veru helpful

Uploaded by

ak2712329
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

PROGRAM - 1

Question :
Write a program using functions to 1. count the number of vowels 2. Search for a character 3.
Display the occurrence of a character, in a string passed as argument to it.

Output :
def count_vowels(s):
count = 0
for char in s:
if char in 'aeiouAEIOU':
count += 1
return count

def search_character(s, ch):


for char in s:
if char == ch:
return True
return False

def display_occurrence(s, ch):


count = 0
for char in s:
if char == ch:
count += 1
return count

string = input("Enter a string: ")


character = input("Enter a character to search: ")

print("Number of vowels:", count_vowels(string))

if search_character(string, character):
print(f"The character '{character}' is found in the string.")
else:
print(f"The character '{character}' is not found in the string.")

print(f"The character '{character}' occurs {display_occurrence(string, character)} time(s) in the


string.")
PROGRAM - 1

You might also like