Skip to content
Tactiverge

Learning Rooms/△ Level 2 · Builder/Computing and algorithms

Python Tutorial for Beginners 3: Integers and Floats - Working with Numeric Data

Corey Schafer · Length: see YouTube · captions on YouTube · nothing loads until you press play

By the end you can…

  • Distinguish int, float, str, bool and list values and predict the type of an expression.
  • Use //, % and / correctly, for example to split seconds into minutes and seconds.
  • Convert text to numbers with int() and float() and explain when conversion fails.
?Predict▶Watch✓Practise⚙Build

Watch it all: no segment has been checked by hand for this video yet.

1.Predict before you press play

What type is the result of 6 / 3 in Python 3?

Pick one before you press play. A wrong guess is fine: it is what makes the video stick.

2.See the idea first

Play with this diagram for a minute. It gives you something to hang the video on.

Loading the interactive…

Can't use the diagram? Read a description instead

The type inspector lists expressions with their Python results: 7 / 2 → 3.5 (float); 6 / 3 → 2.0 (float); 7 // 2 → 3 (int); 135 // 60 → 2 and 135 % 60 → 15 (int); "7" + "2" → '72' (str); "23.5" + 0.4 → TypeError; float("23.5") + 0.4 → 23.9; int("4.2") → ValueError; int(9.99) → 9. A second panel computes any two numbers with any operator and shows the result and its type.

3.Watch, actively

A calm tour of Python's number types, its arithmetic operators and the difference between / and //.

Length: see YouTube · captions on YouTube · source

Nothing loads from YouTube until you press play.

Watch for…

  • → Watch the difference between / and //, and what % (modulo) gives. Notice the type each one produces.

Pause whenever you like. Rewatching a hard minute is a good habit, not a failure.

Can't stream it? Read the idea instead

Python stores whole numbers as integers and numbers with a fractional part as floats. Ordinary division with / always gives a float, while // gives the whole-number part and % the remainder. Floats are stored approximately, so 0.1 + 0.2 is not exactly 0.3.

What the video covers (our own note, written when we verified it): A calm tour of Python's number types, its arithmetic operators and the difference between / and //.

Written by Tactiverge in our own words, not a transcript. The full lesson below explains the idea without the video.

Read it instead

Jot down one thing that surprised you and one question you still have.

Private: saved only on this device, never sent to Tactiverge.

4.Practise what you just saw

These come from the lesson that use this video and are checked on the server. Wrong answers get a hint and another try.

Practice 1

reading = "23.5". Which line gives the number 23.9?

Practice 2

What does "7" + "2" give?

Practice 3

A machine makes 250 parts and packs 12 per box. How many parts are left over (250 % 12)?

parts

Practice 4 · a fresh version every time

A machine makes 26 parts and packs them in boxes of 12. What does Python give for 26 // 12 (full boxes)?

parts

5.Try it yourself

No simulation models this idea yet. The lesson below has an interactive diagram instead.

6.Where engineers use it

Data loggers and serial sensors send readings as text, often with stray characters. Embedded and data code always has a conversion step that can fail, and the failure must be handled rather than ignored.

From the applied view in the lesson int, float, str and list. Checked by automated tests only.

7.Build something with it

Follow-up project

Write a program that takes a total run time in seconds (try 7384) and prints it as 'h min s'. Then add a line that reads a battery voltage stored as the text "3.71", converts it and prints whether it is below 3.5 V.

Where this video lives

In the course catalogue: CSE-210 Python for engineers

The video is by Corey Schafer, embedded from YouTube with privacy-enhanced mode and never autoplayed. The room around it (prompts, notes, practice, projects) is Tactiverge's, written with AI assistance and checked by automated tests only.