Every line of 'if name main python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
13 def main(): 14 """main""" 15 args = sys.argv[1:] 16 17 if len(args) != 1: 18 print('Usage: {} STR'.format(os.path.basename(sys.argv[0]))) 19 sys.exit(1) 20 21 word = args[0] 22 lc_word = word.lower() 23 24 # Method 1: 25 # Create a variable to hold the count 26 # Use a `for` loop to go through each character in the word 27 # If that character is in the list of vowels, increment the counter 28 count = 0 29 for char in word.lower(): 30 if char in 'aeiou': 31 count += 1 32 33 # Method 2: 34 # Create a variable to hold the count 35 # Use a `for` loop to go through the list of vowels 36 # Increment the count with the `str.count` function that will 37 # find how many times the vowel occurs in the word 38 # count = 0 39 # for vowel in "aeiou": 40 # count += lc_word.count(vowel) 41 42 # Method 3: 43 # Use a list comprehension instead of a `for` loop to get a list 44 # of integers which are the counts for each vowel 45 # Then use the `sum` function to add them together 46 # count = sum([lc_word.count(v) for v in "aeiou"]) 47 48 # Method 4: 49 # Replace the list comprehension with a `map` 50 # count = sum(map(lc_word.count, "aeiou")) 51 52 print('There {} {} vowel{} in "{}."'.format( 53 'are' if count > 1 or count == 0 else 'is', 54 count, 55 '' if count == 1 else 's', 56 word))