IQ 61: Determine if a string contains vowels

Поделиться
HTML-код
  • Опубликовано: 21 окт 2024

Комментарии • 3

  • @Sumtoshi
    @Sumtoshi Год назад +1

    # Create a function to test whether or not a character is a vowel
    def is_vowel(char):
    all_vowels = 'aeiouAEIOU'
    return char in all_vowels
    # Take input from the user
    char = input("Enter a character: ")
    # Print result
    if is_vowel(char):
    print(char, "is a vowel.")
    else:
    print(char, "is not a vowel.")

  • @Sumtoshi
    @Sumtoshi Год назад

    And now JS
    // Create a variable that holds the string
    let str = "This is a test!";
    // Iterate through each character in the string
    for (let char of str) {
    // Check for each vowel
    if (char === "a" || char === "e" || char === "i" || char === "o" || char === "u") {
    // If a vowel is found, print it out
    console.log(char);
    }
    }

  • @Sumtoshi
    @Sumtoshi Год назад

    First comment