• 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«The riddle of the ancient storage»

you & mdash; A brave adventurer standing in front of the massive door of an ancient storage. There are three runic pedestals on the door, on which you need to put three magic stones with a certain weight. Legends say that the door will open only if a strict sequence of rules is observed. If you violate the order or use the wrong combination, the trap or the mechanism will simply not work.

rn

rules Discoveries:

rn
    rn
  1. a , & nbsp; b , & nbsp; c ) should be exactly equal to & nbsp; 100 . This is the main condition for activation of the mechanism.
  2. rn
  3. if the total weight is correct (equal to 100), the mechanism checks for Traps. & nbsp; trap & nbsp; it works if the weight of any two stones & nbsp; is the same . The ancients did not tolerate duplicates.
  4. rn
  5. strictly more than 10 . Stones with less weight are considered "immature".
  6. rn
  7. and the last, the most cunning rule: among three stones, though at least would & nbsp; one & nbsp; must have & nbsp; simple & nbsp; weight (simple number). This is a “key” to the castle.
  8. rn rn

    your task & mdash; Write a program that will determine what will happen by the weight of three stones.

    Input format

    one line containing three whole positive The numbers & nbsp; a , & nbsp; b & nbsp; and & nbsp; c , separated by spaces.

    Output format

    depending on the fulfillment of the conditions, the program should derive one of three phrases:

    rn
  9. The storage is open & nbsp; & mdash; If all the conditions for the opening are fulfilled.
  10. rn
  11. trap! & nbsp; & mdash; If the trap has worked for the same stones (provided that their amount is 100).
  12. rn
  13. incorrect combination & mdash; In all other cases (the amount is not equal to 100; or one of the stones & lt; = 10; or there is not a single stone with a simple weight).
  14. rn

    Example

    Input

    17 40 43

    Output

    The storage 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
# Функция для проверки, является ли число простым
def is_prime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

# Считываем веса трех камней
a, b, c = map(int, input().split())

# 1. Проверяем главное условие: суммарный вес должен быть равен 100
if a + b + c != 100:
    print("Неверная комбинация")
else:
    # 2. Проверяем ловушку: вес любых двух камней не должен быть одинаковым
    if a == b or a == c or b == c:
        print("Ловушка!")
    else:
        # 3. Проверяем, что вес каждого камня строго больше 10
        if a <= 10 or b <= 10 or c <= 10:
            print("Неверная комбинация")
        else:
            # 4. Проверяем, что хотя бы один камень имеет простой вес
            if is_prime(a) or is_prime(b) or is_prime(c):
                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, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!