Lab, Lists, Tuples and Strings
7 tasks, easy to hard: Predict, then run, Write it, Complete it, Fix it, Trace it, Refactor it, Mini challenge. Hints come one at a time and you can see each answer. Lab work is saved as practice and earns no XP.
Open the lessonYou can read every task below. Running, checking and saving them needs a free ID.
7 tasks
Task 01 .Type what the program will print, then run it to compare.
Type exactly what this program prints.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 02 .Solve it from the prompt, starting from an empty editor.
Given file_name = " Summer Trip PHOTO.JPG ", print a clean version: no spaces at the ends, all lowercase, and spaces inside replaced with underscores: summer_trip_photo.jpg.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 03 .Fill the marked gaps in the starter code.
Replace each ___ so the program turns 15/06/2024 into 2024-06-15.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 04 .The starter code has a bug. Repair it so the checks pass.
This program should print hello-world, but it prints the original text. Fix it so the results of the methods are kept.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 05 .Fill the table with the variable values, step by step.
Each row is the value of text after it changes. Strings are shown in quotes.
text = " Red, Green "
text = text.strip()
text = text.lower()
text = text.replace(", ", "|")
text = text.upper()Sign in or create a free ID to fill in and check this table.
Task 06 .Rewrite working code to the stated rule, keeping the same output. Rule: Use str.count() instead of counting in a loop.
This program counts the letter s with a loop. Rewrite it with the string method count() and no loop. The output must stay 4.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 07 .A short task that combines this lesson with earlier ones.
The text line = " ana:82, BO:95 ,cy:77 " holds names and scores. Print each player as a title-cased name and score, then the best player:
Ana 82 Bo 95 Cy 77 Best: Bo
Use split(), strip() and title(), and convert scores with int().
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.