📌  相关文章
📜  国际空间研究组织 | ISRO CS 2013 |问题 58(1)

📅  最后修改于: 2023-12-03 15:37:14.965000             🧑  作者: Mango

ISRO CS 2013 - Question 58

This question involves writing a program that reads a string of characters and outputs the count of vowels in the string.

Algorithm
  1. Begin
  2. Read the input string from user
  3. Initialize a counter variable count to 0
  4. Loop through each character in the input string
  5. If the character is a vowel (a, e, i, o, u), increment the counter count
  6. Output the value of count
  7. End
Solution
# function to count vowels in a string
def count_vowels(string):
    count = 0
    for char in string:
        if char.lower() in ['a', 'e', 'i', 'o', 'u']:
            count += 1
    return count

# main program
if __name__ == '__main__':
    input_string = input("Enter a string of characters: ")
    num_vowels = count_vowels(input_string)
    print("Number of vowels in the string:", num_vowels)

The count_vowels function takes a string as input, loops through each character in the string and increments the counter variable count if the character is a vowel. The main program reads the input string from the user, calls the count_vowels function and outputs the count of vowels in the string.

This program will work for all types of input strings and is the most efficient solution to solve the problem.