Chapter 0 · Section 2 practice

Strings and Clear Output

Work from question 1 to 10. Write your code, click Run Code, review the result, then click Submit attempt. An attempt may be wrong: reference answers become available after you submit all 10. Each Python box is independent. Submission progress is saved in this browser.

Submitted: 0 / 10

1. Create a string

Warm-up. Store your example name Alex in a variable and print it. Print its type on a second line.

Write your answer, then run it.

2. Join two names

Warm-up. Join first_name and last_name with a space between them. Print the full name.

Write your answer, then run it.

3. Repeat text

Warm-up. Use string multiplication to print Go! three times, with spaces between the words.

Write your answer, then run it.

4. A birthday message

Build your skills. Using an f-string, print Next year Alex will be 17. Calculate the next age inside the braces.

Write your answer, then run it.

5. Display a price

Build your skills. Print Price: HK$8.50 using an f-string and two decimal places. Then print the stored price itself.

Write your answer, then run it.

6. Numeric text

Build your skills. Convert the text values to integers and print their numeric sum. Do not join the text.

Write your answer, then run it.

7. A bill from form inputs

Build your skills. Convert the price text to float and quantity text to int. Print Bill: HK$37.50.

Write your answer, then run it.

8. Clean a label

Challenge. Remove the surrounding spaces and convert the label to uppercase. Print the clean label between square brackets so extra spaces are visible.

Write your answer, then run it.

9. Keep an identifier as text

Challenge. The student identifier is 0042. Keep its leading zeros. Print Student: 0042; on a second line show what int(student_id) would produce.

Write your answer, then run it.

10. A complete receipt

Challenge. Clean the item name, convert the numeric text, and print PEN: 3 items, HK$13.50 using an f-string.

Write your answer, then run it.

Reference answers are locked until all 10 attempts are submitted.