• 1
    Input and Output Data
    • Tasks
  • 2
    Conditions
    • Tasks
  • 3
    For Loop
    • Tasks
  • 4
    Strings
    • Tasks
  • 5
    While Loop
    • Tasks
  • 6
    Lists
    • Tasks
  • 7
    Two-Dimensional Arrays
    • Tasks
  • 8
    Dictionaries
    • Tasks
  • 9
    Sets
    • Tasks
  • 10
    Functions and Recursion
    • Tasks
  • к

Занятие 3. FOR cycle

Difficulty level:

Task«The amount of vowels»

you & mdash; A special agent under the cover that is trying to penetrate the secret object. The only way to get inside & mdash; Enter the correct code phrase into the access terminal. The security system of the object is very cunning: it does not check the phrase itself, but analyzes its structure. The door will open only if the number of vowels in the introduced phrase is equal to the secret number & mdash; 7.

rn

Your task: & nbsp; write a program that imitates the work of this terminal. The program must request the user input of the code phrase. Then it should calculate the number of vowels in this phrase and, depending on the result, withdraw one of two messages: “access is allowed” or “access is prohibited”.

rn

Rules:

rn
    rn
  1. only the following vowels are considered: & nbsp; a, e, i, o, o, o, o, o, o, o U .
  2. rn
  3. the register of letters does not matter (that is, 'a' is considered the same as 'a').

    Input format

    Passol phrase (type: line)

    Output format

    The result of the check (type: line)

    Example

    Input

    a Quick Brown Fox Jumps High

    Output

    Access is allowed

    Hint

    There will be no clue here, decide for yourself!

main.py
Test 1
Test 2
Test 3
Test 4
Test 5
Test 6
Test 7
Test 8
Test 9
Test 10
Developer’s solution
# Создаем переменную-счетчик для гласных и устанавливаем ее в 0
vowel_count = 0

# Определяем строку, содержащую все гласные в нижнем регистре для удобства проверки
vowels = "aeiou"

# Запрашиваем у пользователя ввод кодовой фразы
secret_phrase = input()

# Запускаем цикл, который перебирает каждый символ во введенной строке
for char in secret_phrase:
    # Проверяем, является ли текущий символ (приведенный к нижнему регистру) одной из гласных
    if char.lower() in vowels:
        # Если это гласная, увеличиваем наш счетчик на 1
        vowel_count += 1

# После завершения цикла проверяем, равно ли итоговое количество гласных секретному числу 7
if vowel_count == 7:
    # Если равно, выводим сообщение об успехе
    print("Доступ разрешен")
else:
    # Если не равно, выводим сообщение об отказе
    print("Доступ запрещен")

🎉 Congratulations! 🎉

You did an excellent job with the task! It was a challenging problem, but you found the correct solution. You are one step closer to mastering programming! Keep up the good work, because every stage you pass makes you even stronger.

AD

Advertisement

red-snake blue-snake green-snake

Running your code...

Помощник ИИ

Привет! Я твой помощник по программированию. Задавай любые вопросы по Python, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!