• 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
  • к

Занятие 2. Conditions

Difficulty level:

Task«Cryptographic castle»

you & mdash; A brave adventurer, and during your wanderings, you found a mysterious chest in the dungeon of an ancient castle. The chest is locked on a magic cryptographic lock that requires the entry of three secret numbers. The legend drawn on the wall says that the lock will open if & nbsp; at least one & nbsp; out of two conditions:

rn
  • Three numbers introduced into the lock form & nbsp; strictly increasing & nbsp; sequence (that is, each next number larger than the previous one). 14pt; "> all three & nbsp; the numbers are & nbsp; simple . rn

    recall that a simple number & mdash; This natural number is more than 1, which is divided without a trace by only 1 and itself (for example, 2, 3, 5, 7, 11).

    rn

    your task & mdash; Write a program that will help you quickly check the combinations of numbers. The program should be determined by three intended integers whether the castle will open.

    Input format

    Three integers (Integer), each is introduced from the new line. These are secret numbers for the castle.

    Output format

    Line (String) with the result: "The lock is open" or "Castle locked".

    Example

    Input

    3
    5
    7

    Output

    The castle is open

    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
    # Запрашиваем у пользователя три целых числа
    a = int(input())
    b = int(input())
    c = int(input())
    
    # Проверка первого условия: строго возрастающая последовательность
    # Эта переменная будет True, если a < b и b < c, иначе False
    is_increasing = a < b < c
    
    # Проверка второго условия: все три числа являются простыми
    # Создаем флаги для каждого числа, по умолчанию считаем их простыми
    a_is_prime = True
    b_is_prime = True
    c_is_prime = True
    
    # Проверяем число 'a' на простоту
    if a <= 1:
        # Числа меньше или равные 1 не являются простыми
        a_is_prime = False
    else:
        # Перебираем все возможные делители от 2 до a-1
        for i in range(2, a):
            # Если нашелся делитель без остатка, число не простое
            if a % i == 0:
                a_is_prime = False
                break # Прерываем цикл, так как дальше проверять нет смысла
    
    # Проверяем число 'b' на простоту (логика аналогична)
    if b <= 1:
        b_is_prime = False
    else:
        for i in range(2, b):
            if b % i == 0:
                b_is_prime = False
                break
    
    # Проверяем число 'c' на простоту (логика аналогична)
    if c <= 1:
        c_is_prime = False
    else:
        for i in range(2, c):
            if c % i == 0:
                c_is_prime = False
                break
    
    # Итоговый флаг для второго условия: будет True, только если все три флага True
    all_are_prime = a_is_prime and b_is_prime and c_is_prime
    
    #  Финальное решение 
    # Замок откроется, если выполнено хотя бы одно из двух условий (оператор or)
    if is_increasing or all_are_prime:
        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, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!