Files
curriculum/1.solar-system/2.first-light/06.the-translator/index.md

816 B
Raw Blame History

type, title, xp, duration, difficulty
type title xp duration difficulty
challenge The Translator 50 25 2

The Translator

[INCOMING — Mission Control, Earth]

Cadet, when input comes in as text (a str), you can't do math with it directly. You have to translate it to a number.

Three converters:

  • int("42")42
  • float("3.14")3.14
  • str(42)"42"

Implement years_until(age) that returns 100 - age as an int. The argument may arrive as either int or str — handle both by calling int() on it first.

[END TRANSMISSION]

Your Task

Open starter/starter.py. Convert age with int(), then return 100 - age.

Objectives

  • years_until(25) returns 75
  • years_until("25") also returns 75 (handles string input)
  • Works for any integer age 0100