Practice · Python

Practice Type Conversion

Convert between int, float, str, and bool explicitly with int()/float()/str()/bool() and know when conversion loses information or fails.

Type Conversionwarming python…

Calculate a sports score with type conversion

Write a function calculate_score(num_str, multiplier) that receives a numeric string num_str (e.g., "10") and a numeric multiplier (float or int). The function should:

  1. Convert num_str to an integer.
  2. Multiply it by multiplier.
  3. Truncate the product to an integer (drop any decimal part).
  4. Return a message string exactly formatted as "Final score: X" where X is the truncated integer.

Examples

calculate_score("10", 2.5)  # returns "Final score: 25"
calculate_score("3", 1.9)   # returns "Final score: 5"
Press Run to see output, or Check to grade against the tests.

Want a whole course built around type conversion?

Start my path — free

Adaptive practice, streaks, projects with real code review. Free tier gates AI help, never content.