Rullst AcademyRullst Academy/Lesson
Python: from first line to project · Lesson 03 / 12

Input is not a promise

A field or keyboard may provide "15". Before calculating, we need to understand what arrived and what can go wrong.

Learning paths9 min

Let's discover together

  1. 1

    input() reads a keyboard line and returns text. Our examples use raw = "15" so you can repeat exactly the same trial.

  2. 2

    int(raw) attempts to convert that text to an integer. After conversion, 15 + 5 gives 20. Without it, raw + "5" joins strings and gives "155".

  3. 3

    int("fifteen") raises ValueError. int("-3") succeeds, but a negative duration may be invalid for our mission. Conversion and checking a rule are separate steps.

  4. 4

    For now, test known inputs. Later we will handle ValueError with try/except and test boundaries. Do not hide invalid input by choosing an arbitrary number.

✦
YOUR MISSION

Convert numeric text and recognise invalid input without confusing conversion with validation.

Now it's your turn

Discovery workshop

Read, predict, check

Compare the two versions. Show result reveals a prepared output: this panel does not run Python. Then practise with the activity file.
Mini experiment

Learning simulation: compare cards and check your predictions. The browser is not compiling Rust or starting a server.

raw = "15"
minutes = int(raw)
print(minutes + 5)
Build your answers and check when you are ready.
A moment to understand

Does converting "-3" with int prove the duration is suitable?

I need a hint

Being able to represent a value does not mean accepting it in every situation.

Loading your journey…

Take it with you

Replace raw = "15" with raw = input("Minutes: "). Run and enter 20; then repeat with a word. Record the error type without personal data.

PYTHON · .py

Your Python workbench

Here you read and predict prepared outputs. To run the actual code, download the activity file, edit it on your computer and use Python. Rullst Academy grades lesson answers; it does not verify local execution.

Save and run

Extract the activity ZIP into its own folder. Open a terminal there and use your system’s command. If downloading your edited file separately, use its actual name in the command. Save before running again.

Windows
python lesson.py
macOS / Ubuntu
python3 lesson.py
My files and GitHub

The editor keeps a local draft and can send a .py file to GitHub with your confirmation. Download your edited code to preserve it. The ZIP is starter material; for the final project, also publish data and test files following PUBLISH.md.

At your own pace

My files and GitHub

Every lesson can become your own record: code, notes or a practice plan. Saving a file to GitHub is optional and does not change your XP.

Student guide

The editor and downloads open when this lesson is available to your account. Check access below or return to the track map.

Checking your access to this lesson…

Rullstpetbot

AI can make mistakes. Check the lesson material.