Given word = "pizza" and event = "PARTY", print PIZZA party โ the first word uppercased, a space, then the second word lowercased. Use an f-string and methods together!
word = "pizza"
event = "PARTY"
print(f"{word.upper()} {event.lower()}")
๐ต๏ธ
Task 4: Free Play โ Secret Initials
Creative
Store your full name in a variable. Use indexing ([0]) and slicing to print your first initial, your last character, and the first 3 letters. Experiment!
๐๏ธ Extra Practice โ Drill Time!
Text is everywhere in programming โ names, messages, passwords, chat. The only way to get fast at it is repetition, so here are plenty of reps.
๐
Task 5: How Long Is It?
Easy
len(text) counts the characters. Make word = "elephant" and print its length, then print it in ALL CAPS with .upper(), then in lowercase with .lower().
8
ELEPHANT
elephant
word = "elephant"
print(len(word))
print(word.upper())
print(word.lower())
โ๏ธ
Task 6: Slice It Up
Medium
Slicing takes a piece of text: text[0:3] means characters 0, 1 and 2. With word = "programming", print the first three letters, then the last four letters (word[-4:]), then every letter from position 3 to 7.
pro
ming
gram
word = "programming"
print(word[0:3])
print(word[-4:])
print(word[3:7])
๐
Task 7: Search Inside Text
Medium
With sentence = "the quick brown fox", print: whether it contains "quick" (use in), the position of "brown" (use .find()), and how many times the letter "o" appears (use .count()).
True
10
2
sentence = "the quick brown fox"
print("quick" in sentence)
print(sentence.find("brown"))
print(sentence.count("o"))
๐
Task 8: Replace and Repeat
Easy
Text has superpowers: * repeats it and .replace() swaps parts. Print "ha" * 3, then take "I like cats" and print it with cats replaced by dogs.
hahaha
I like dogs
print("ha" * 3)
print("I like cats".replace("cats", "dogs"))
๐งน
Task 9: Clean Up Messy Input
Medium
Users type messy text. Take messy = " Hello World " and print: the messy value inside two pipes | so you can see the spaces, then the cleaned version with .strip() inside pipes too.
Using an f-string, build one sentence from name = "Sam", subject = "math" and score = 92:
Sam scored 92% in math!
name = "Sam"
subject = "math"
score = 92
print(f"{name} scored {score}% in {subject}!")
๐
Task 11: Title Case Machine
Medium
Take messy_name = "aLiCe wOnDeRlAnD" and print it properly capitalized using .title(). Then print just the first letter of each word joined together (AW) using slicing and .split() โ or by hand, your choice.
Write a mini cipher. Take secret = "python rules" and print, in order: the message reversed (secret[::-1]), the message with every space replaced by _, and the message in caps with each letter separated by a dash (hint: "-".join(...)).
Store a chorus line in a variable and print it three times using * or three prints, then print a version SHOUTED in caps, a whispered lowercase version, and a version with one word swapped out. Have fun with it! ๐ถ