תנאיםConditions
if, elif, else, השוואות, and/or/not ואמת/שקר.
if, elif, else, comparisons, and/or/not and truthiness.
זוגי או אי-זוגיEven or odd
תזכורת: מה ביקשוReminder: the task
קלטו מספר שלם והדפיסו even אם הוא זוגי ו-odd אם לא.
Read a whole number and print even if it's even, odd otherwise.
הפתרון המלא והפלט שלוFull solution and its output
n = int(input())
if n % 2 == 0:
print("even")
else:
print("odd")7 odd
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
ציון במיליםGrade in words
תזכורת: מה ביקשוReminder: the task
קלטו ציון (0-100) והדפיסו: 90+ excellent, 75-89 good, 55-74 pass, מתחת fail.
Read a score (0-100) and print: 90+ excellent, 75-89 good, 55-74 pass, below that fail.
הפתרון המלא והפלט שלוFull solution and its output
s = int(input())
if s >= 90:
print("excellent")
elif s >= 75:
print("good")
elif s >= 55:
print("pass")
else:
print("fail")82 good
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
שנה מעוברתLeap year
תזכורת: מה ביקשוReminder: the task
קלטו שנה והדפיסו True אם היא מעוברת: מתחלקת ב-4, אבל לא ב-100, אלא אם היא מתחלקת ב-400.
Read a year and print True if it's a leap year: divisible by 4, but not by 100, unless divisible by 400.
הפתרון המלא והפלט שלוFull solution and its output
y = int(input())
leap = (y % 4 == 0 and y % 100 != 0) or y % 400 == 0
print(leap)2000 True
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
כניסה למערכתLog in
תזכורת: מה ביקשוReminder: the task
משתמש נכון: admin, סיסמה נכונה: py123. קלטו שם וסיסמה. אם שניהם נכונים הדפיסו welcome; אם רק השם נכון wrong password; אחרת unknown user.
Correct user: admin, password: py123. Read a name and password. If both are right print welcome; if only the name is right wrong password; otherwise unknown user.
הפתרון המלא והפלט שלוFull solution and its output
user = input()
pw = input()
if user == "admin":
if pw == "py123":
print("welcome")
else:
print("wrong password")
else:
print("unknown user")admin abc wrong password
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
מדף, צעד 5: תגית לספרShelf, step 5: tag a book
תזכורת: מה ביקשוReminder: the task
קלטו שם ספר, מספר עמודים ודירוג (1-5). הדפיסו <שם>: ואחריו תגית: ⭐ must read אם הדירוג 5, 📏 long אם יותר מ-500 עמודים (ודירוג פחות מ-5), אחרת 📖 regular.
Read a title, page count and rating (1-5). Print <title>: followed by a tag: ⭐ must read if rating is 5, 📏 long if over 500 pages (and rating under 5), otherwise 📖 regular.
הפתרון המלא והפלט שלוFull solution and its output
title = input()
pages = int(input())
rating = int(input())
if rating == 5:
tag = "⭐ must read"
elif pages > 500:
tag = "📏 long"
else:
tag = "📖 regular"
print(f"{title}: {tag}")Dune 600 4 Dune: 📏 long
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
סוג משולשTriangle type
תזכורת: מה ביקשוReminder: the task
קלטו שלוש צלעות. אם הן לא יכולות ליצור משולש (צלע אחת ≥ סכום שתי האחרות) הדפיסו invalid. אחרת: equilateral (שלוש שוות), isosceles (שתיים), scalene (אף אחת).
Read three sides. If they can't form a triangle (one side ≥ the sum of the other two) print invalid. Otherwise: equilateral (all equal), isosceles (two), scalene (none).
הפתרון המלא והפלט שלוFull solution and its output
a = int(input())
b = int(input())
c = int(input())
if a >= b + c or b >= a + c or c >= a + b:
print("invalid")
elif a == b == c:
print("equilateral")
elif a == b or b == c or a == c:
print("isosceles")
else:
print("scalene")5 5 8 isosceles
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
אבן, נייר, מספרייםRock, paper, scissors
תזכורת: מה ביקשוReminder: the task
קלטו שתי בחירות (rock / paper / scissors) של שחקן 1 ושחקן 2. הדפיסו tie, player 1 או player 2 לפי המנצח.
Read two choices (rock / paper / scissors) for player 1 and player 2. Print tie, player 1 or player 2 for the winner.
הפתרון המלא והפלט שלוFull solution and its output
p1 = input().strip().lower()
p2 = input().strip().lower()
if p1 == p2:
print("tie")
elif (p1 == "rock" and p2 == "scissors") or (p1 == "scissors" and p2 == "paper") or (p1 == "paper" and p2 == "rock"):
print("player 1")
else:
print("player 2")Rock paper player 2
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.