Python practice: Modern String Formatting & Input
Chapter 4 · 8 questions · included in full access
Question 1 · easy
f-string variable interpolation
Solve it in your browserGiven
rep = "Asha"andsales = 14, use an f-string to print exactly:Rep Asha closed 14 deals.Question 2 · easy
Currency format specifier
Solve it in your browserGiven
revenue = 1485900.75, print it formatted with thousands commas and 2 decimal places usingf"₹{revenue:,.2f}":Question 3 · easy
Read user input
Solve it in your browserRead a customer name using
customer = input()and printf"Account created for: {customer}":Question 4 · easy
String indexing
Solve it in your browserGiven
code = "INV-2026-981", print the first charactercode[0]on line 1, and the last charactercode[-1]on line 2:Question 5 · easy
Extract SKU prefix with slicing
Solve it in your browserGiven
sku = "PROD-ELECTRONICS-44", slice out the first 4 characterssku[0:4]and print them:Question 6 · easy
Trim whitespace with .strip()
Solve it in your browserGiven
raw_name = " Priya Sharma ", strip leading and trailing whitespace and print the cleaned string:Question 7 · easy
Normalize string casing
Solve it in your browserGiven
city = "mumbai", print it in uppercase with.upper()on line 1, and title-case with.title()on line 2:Question 8 · medium
Clean telephone hyphens
Solve it in your browserGiven
phone = "022-555-0199", replace all hyphens with empty strings""using.replace("-", "")and print the digits:
These questions are part of full access.
The first chapters of every track are free. Full access is a one-time payment.
See pricing