
Bigyan K. answered 04/20/24
MS in Data Analytics
def count(s, ch):
count = 0
for char in s:
if char == ch:
count += 1
return count
# Test program
def main():
# Read input string and character
input_string = input("Enter a string: ")
input_char = input("Enter a character: ")
# Count occurrences of the character in the string
occurrences = count(input_string, input_char)
# Display the result
print(f"The character '{input_char}' occurs {occurrences} time(s) in the string.")
if __name__ == "__main__":
main()