Night 15: Loud and quiet
لقد أنهيت هذه الليلة بالفعل باستخدام Python أو الشيفرة الكاذبة. وهي تُحتسب لكلتيهما. تدرّب مرة أخرى إن شئت.
Tonight: loud and quiet
- Welcome to week 3: words and secrets!
- Tonight your pet speaks loud and quiet.
- You will learn one thing: tools for text.
Words for tonight
| Word | Meaning |
|---|---|
| upper case | capital letters: A B C |
| lower case | small letters: a b c |
| length | how many characters are in a text |
Loud and quiet
- Put a dot and the tool name after the text.
word = "Hello"
print(word.upper())
print(word.lower())
print(word)
worditself does not change..upper()and.lower()give a new text.
Count the characters
lencounts the characters in a text. Spaces count too.
name = "Lumi"
print(len(name))
print(len("Good night"))
| Text | len |
|---|---|
"Kit" |
3 |
"Good night" |
10 |
"" |
0 |
Compare without worrying about capitals
- For Python,
"YES"and"yes"are different. - Make both lower case, then compare:
answer = "YES"
if answer.lower() == "yes":
print("OK!")
- Now make your pet shout and whisper!
الصعوبة 1/5 · 100 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
Your pet shouts! Read a word with input(). Print it in capital letters with ! after it. hello becomes HELLO!.
اضغط تشغيل لرؤية المخرجات هنا.
الصعوبة 1/5 · 100 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
Now your pet whispers. Read a word and print it in small letters. HELLO becomes hello.
اضغط تشغيل لرؤية المخرجات هنا.
الصعوبة 2/5 · 140 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
Read a name. Print the name, has, the number of letters, and letters. For Kit the output is Kit has 3 letters.
اضغط تشغيل لرؤية المخرجات هنا.
الصعوبة 2/5 · 140 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
Read two words. If they are the same word, even with different capitals (YES و yes), print Same!. Otherwise print Different.
اضغط تشغيل لرؤية المخرجات هنا.