Python practice: Variables & Data Types

Chapter 2 · 8 questions · free to solve

  1. Question 1 · easy

    Store order price

    Create a variable price = 250 and quantity = 3. Multiply them to compute total and print total:

    Solve it in your browser
  2. Question 2 · easy

    Inspect data types

    Create units = 15 and rate = 45.5. Print type(units) on the first line and type(rate) on the second line:

    Solve it in your browser
  3. Question 3 · easy

    Type casting string to integer

    Given raw input strings raw_price = "450" and raw_tax = "81", cast them to integers and print their numeric sum 531:

    Solve it in your browser
  4. Question 4 · easy

    Type casting float to string

    Convert decimal margin = 0.25 into a string using str(margin) and print f"Margin: {str(margin)}":

    Solve it in your browser
  5. Question 5 · easy

    Update variable with +=

    Initialize balance = 1000. Add 250 using +=, then add another 100 using +=. Print balance:

    Solve it in your browser
  6. Question 6 · easy

    Boolean variable flag

    Create a boolean flag is_delivered = True. Print the variable and its type on separate lines:

    Solve it in your browser
  7. Question 7 · easy

    Snake_case naming convention

    Create three variables: unit_cost = 80, sales_tax = 14, and final_price = unit_cost + sales_tax. Print final_price:

    Solve it in your browser
  8. Question 8 · medium

    Gross margin calculation

    Given revenue = 50000 and cogs = 35000, compute gross_profit = revenue - cogs and margin_pct = gross_profit / revenue. Print margin_pct:

    Solve it in your browser

These questions are free.

Make a free account to solve them, with instant checking and an AI tutor for hints.

Start free