Python practice: Modern String Formatting & Input

Chapter 4 · 8 questions · included in full access

  1. Question 1 · easy

    f-string variable interpolation

    Given rep = "Asha" and sales = 14, use an f-string to print exactly:

    Rep Asha closed 14 deals.
    
    Solve it in your browser
  2. Question 2 · easy

    Currency format specifier

    Given revenue = 1485900.75, print it formatted with thousands commas and 2 decimal places using f"₹{revenue:,.2f}":

    Solve it in your browser
  3. Question 3 · easy

    Read user input

    Read a customer name using customer = input() and print f"Account created for: {customer}":

    Solve it in your browser
  4. Question 4 · easy

    String indexing

    Given code = "INV-2026-981", print the first character code[0] on line 1, and the last character code[-1] on line 2:

    Solve it in your browser
  5. Question 5 · easy

    Extract SKU prefix with slicing

    Given sku = "PROD-ELECTRONICS-44", slice out the first 4 characters sku[0:4] and print them:

    Solve it in your browser
  6. Question 6 · easy

    Trim whitespace with .strip()

    Given raw_name = " Priya Sharma ", strip leading and trailing whitespace and print the cleaned string:

    Solve it in your browser
  7. Question 7 · easy

    Normalize string casing

    Given city = "mumbai", print it in uppercase with .upper() on line 1, and title-case with .title() on line 2:

    Solve it in your browser
  8. Question 8 · medium

    Clean telephone hyphens

    Given phone = "022-555-0199", replace all hyphens with empty strings "" using .replace("-", "") and print the digits:

    Solve it in your browser

These questions are part of full access.

The first chapters of every track are free. Full access is a one-time payment.

See pricing