מחרוזותStrings
אינדקסים, חיתוך, מתודות של מחרוזות ועיצוב פלט.
Indexing, slicing, string methods and formatting output.
ראשי תיבותInitials
תזכורת: מה ביקשוReminder: the task
קלטו שם פרטי ושם משפחה (שתי שורות) והדפיסו ראשי תיבות באותיות גדולות עם נקודות, למשל N.L.
Read a first and last name (two lines) and print uppercase initials with dots, e.g. N.L.
הפתרון המלא והפלט שלוFull solution and its output
first = input()
last = input()
print(f"{first[0]}.{last[0]}.".upper())noa levi N.L.
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
ניקוי שם ספרClean a book title
תזכורת: מה ביקשוReminder: the task
קלטו שם ספר שהוקלד ברישול (רווחים בקצוות, אותיות מעורבבות). הדפיסו אותו נקי: בלי רווחים בקצוות, כל מילה באות גדולה.
Read a sloppily typed book title (spaces at the ends, mixed case). Print it clean: no spaces at the ends, each word capitalised.
הפתרון המלא והפלט שלוFull solution and its output
raw = input()
print(raw.strip().title())tHE liTTle PRINCE The Little Prince
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
פלינדרוםPalindrome
תזכורת: מה ביקשוReminder: the task
קלטו מילה והדפיסו True אם היא נקראת אותו דבר משני הכיוונים (בלי להתחשב באותיות גדולות), אחרת False.
Read a word and print True if it reads the same both ways (ignoring case), otherwise False.
הפתרון המלא והפלט שלוFull solution and its output
w = input().lower()
print(w == w[::-1])Racecar True
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
סופר תנועותVowel counter
תזכורת: מה ביקשוReminder: the task
קלטו משפט באנגלית והדפיסו כמה תנועות (a, e, i, o, u) יש בו, בלי להתחשב באותיות גדולות. בלי לולאות: רק count.
Read an English sentence and print how many vowels (a, e, i, o, u) it has, ignoring case. No loops: just count.
הפתרון המלא והפלט שלוFull solution and its output
s = input().lower()
print(s.count("a") + s.count("e") + s.count("i") + s.count("o") + s.count("u"))The Little Prince lives on a planet 11
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
מדף, צעד 4: שורת ספר מיושרתShelf, step 4: an aligned book row
תזכורת: מה ביקשוReminder: the task
קלטו שם ספר (מלוכלך) ומספר עמודים. נקו את השם (strip + title) והדפיסו שורה אחת: השם מיושר לשמאל ברוחב 20, |, ומספר העמודים מיושר לימין ברוחב 5.
Read a (messy) book title and a page count. Clean the title (strip + title) and print one row: the title left-aligned in 20 characters, |, and the pages right-aligned in 5.
הפתרון המלא והפלט שלוFull solution and its output
title = input().strip().title()
pages = int(input())
print(f"{title:<20}|{pages:>5}")dune 412 Dune | 412
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
הסתרת אימיילMask an email
תזכורת: מה ביקשוReminder: the task
קלטו כתובת אימייל והדפיסו אותה מוסתרת: התו הראשון, אחריו ***, ואז מה-@ והלאה. noa.levi@example.com → n***@example.com.
Read an email and print it masked: the first character, then ***, then from @ onwards. noa.levi@example.com → n***@example.com.
הפתרון המלא והפלט שלוFull solution and its output
email = input().strip()
at = email.find("@")
print(email[0] + "***" + email[at:])noa.levi@example.com n***@example.com
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.
מילים הפוכותReverse the words
תזכורת: מה ביקשוReminder: the task
קלטו משפט והדפיסו את המילים בסדר הפוך (לא את האותיות). I love good books → books good love I.
Read a sentence and print its words in reverse order (not the letters). I love good books → books good love I.
הפתרון המלא והפלט שלוFull solution and its output
words = input().split()
print(" ".join(words[::-1]))I love good books books good love I
יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.