← Back to course
Code Crew G4 / Week 05 / Wednesday
3/6
Week 05 Β· Strings up close

Wednesday

Big letters, small letters
// Letter by letter
⏱ about 15 min

Wednesday: Big letters, small letters

Rocket asks the new pilot, "Ready to dock?" The pilot types Yes with a capital Y. Rocket's program checks for "yes" and says the pilot is not ready.

"But I said yes!" the pilot calls over the radio. Raven looks at the check. "What do you notice about the first letter?"

Nova shows two words side by side: Yes and yes. "Would you like a hint? To Python, a big Y and a small y are different. You could make them match first."

upper and lower

upper makes a copy of a string in capital letters. lower makes a copy in small letters.

Write the string, a dot, the word, and empty brackets.

msg = "Docking at Bay 2"
print(msg.upper())
print(msg.lower())
print(msg)
The screen shows
DOCKING AT BAY 2
docking at bay 2
Docking at Bay 2
  • Digits, spaces and symbols do not change.
  • upper and lower make a copy. The original string stays the same, as the last line shows.
  • To keep the change, store it: msg = msg.upper()

Fix the yes check

answer = "Yes"
if answer.lower() == "yes":
    print("Cleared to dock")
else:
    print("Please wait")
The screen shows
Cleared to dock

answer.lower() turns Yes into yes before the check. Now YES, Yes and yes all work.

MAKE IT SHOUT
  • Read the question.
  • Tap your answer.
What does print("Bay 7 ready".upper()) show?
answer holdsDoes answer.lower() == "yes" give True?
"YES"?
"yes"?
"Yes!"?
"y"?
WHY THIS EXERCISElower fixes capitals, but not extra characters. Testing tricky answers finds the limits.
name = "raven"
name.upper()
print(name)
DID IT CHANGE?
  • Read the question.
  • Tap your answer.
What does the program above show?
Try it
Write your favorite space word in small letters.
Then write what .upper() would give.
shout = "go Team 4"
print(shout.upper())
print(shout.lower())
loud = shout.upper()
print(loud[0:2])
print(shout)
BIG OR SMALL?
  • Read the question.
  • Tap your answer.
What does line 2 show?
What does line 3 show?
What does line 5 show?
What does the last line show?
answer holdsDoes answer.upper() == "NO" give True?
"no"?
"No"?
"nope"?
"NO " (with a space at the end)?
WHY THIS EXERCISEupper fixes the case, but extra letters or spaces still make it different.
How many characters change when "Bay 12".upper() runs?
WHY THIS EXERCISEOnly the small a and the small y become capitals.

Nice work! Tomorrow you will search inside strings with in.

← Tuesday