3.1. Numeric Int
Represents an integer
Could be both signed and unsigned
Default
intsize is 64 bitPython automatically extends
intwhen need bigger number
Example:
>>> value = 1
>>> temperature = 21
>>> distance = 1000
3.1.1. Syntax
Signed and Unsigned
>>> data = 1
>>> data = +1
>>> data = -1
3.1.2. Thousands Separator
Use
_for thousand separatorYou can use
_for easier read especially with big numbers
You can use _ for easier read especially with big numbers:
>>> million = 1000000
>>> million = 1_000_000
The underscore character _ will not change the value of the number.
Python will simply ignore it. So it could be used for better readability:
>>> million = 1_000_000
>>> print(million)
1000000
3.1.3. Conversion
Builtin function
int()converts argument tointIt is not rounding
Works with strings if they have numbers and
+,-,_(underscore)
Builtin function int() converts argument to int:
>>> int(1.0)
1
>>>
>>> int(-1.0)
-1
>>> int('1')
1
>>>
>>> int('-1')
-1
Builtin function int() fails when in argument there are parameters
other than a digit, + or - sign and _:
>>> int('1.0')
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: '1.0'
3.1.4. Rounding
Builtin function
int()does not round numbers - only converts tointUse
round()for numbers rounding
Builtin function int() does not round numbers, it just cuts off decimals:
>>> int(1.11)
1
>>>
>>> int(1.99)
1
Builtin function round() does that:
>>> round(1.11)
1
>>>
>>> round(1.99)
2
3.1.5. Use Case - 1
>>> SECOND = 1
>>> MINUTE = 60 * SECOND
>>> HOUR = 60 * MINUTE
>>> DAY = 24 * HOUR
>>>
>>>
>>> duration = 123456 * SECOND
>>>
>>> duration // DAY
1
>>> duration // HOUR
34
>>> duration // MINUTE
2057
>>> duration // SECOND
123456
3.1.6. Use Case - 2
>>> m = 1
>>> km = 1000 * m
>>> mi = 1652 * m
>>>
>>>
>>> distance = 123*mi
>>>
>>> distance // m
203196
>>> distance // km
203
3.1.7. Use Case - 3
>>> PLN = 1
>>> EUR = 4.71 * PLN # 2023-03-19 17:00 GMT+1
>>> USD = 4.41 * PLN # 2023-03-19 17:00 GMT+1
>>>
>>>
>>> price = 100*PLN
>>>
>>> round(price // EUR)
21
>>> round(price // USD)
22
3.1.8. Assignments
# %% About
# - Name: Numeric Int Sub
# - Difficulty: easy
# - Lines: 1
# - Minutes: 2
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% English
# 1. Alice was born in year 1988
# 2. Assume it's year 2025 now
# 3. Define variable `result: float` with age of Alice
# 4. Run doctests - all must succeed
# %% Polish
# 1. Alice urodziła się w roku 1988
# 2. Przyjmij, że obecnie jest rok 2025
# 3. Zdefiniuj zmienną `result: float` z wiekiem Alice
# 4. Uruchom doctesty - wszystkie muszą się powieść
# %% Expected
# >>> result
# 37
# %% Hints
# - `-` - sub operator
# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'
>>> assert result is not Ellipsis, \
'Variable `result` has an invalid value; assign result of your program to it.'
>>> assert type(result) is int, \
'Variable `result` has an invalid type; expected: `int`.'
>>> assert result == 37, \
'Variable `result` has invalid value. Check your calculation.'
"""
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`
# %% Imports
# %% Types
result: int
# %% Data
BIRTHDATE = 1988
TODAY = 2025
# %% Result
result = ...
# %% About
# - Name: Numeric Int Sub
# - Difficulty: easy
# - Lines: 1
# - Minutes: 2
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% English
# 1. How many full years is in the period of 3022 days
# 2. Define variable `result` with the solution
# 3. Assume year is 365 days
# 4. Run doctests - all must succeed
# %% Polish
# 1. Ile pełnych lat mieści się w okresie 3022 dni?
# 2. Zdefiniuj zmienną `result` z rozwiązaniem
# 3. Przyjmij, że rok to 365 dni
# 4. Uruchom doctesty - wszystkie muszą się powieść
# %% Expected
# >>> result
# 8
# %% Hints
# - `//` - floordiv operator
# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'
>>> assert result is not Ellipsis, \
'Variable `result` has an invalid value; assign result of your program to it.'
>>> assert type(result) is int, \
'Variable `result` has an invalid type; expected: `int`.'
>>> assert result == 8, \
'Variable `result` has invalid value. Check your calculation.'
"""
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`
# %% Imports
# %% Types
result: int
# %% Data
PERIOD = 3022
YEAR = 365
# %% Result
result = ...
# %% About
# - Name: Numeric Int Floordiv
# - Difficulty: easy
# - Lines: 2
# - Minutes: 3
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% English
# 1. Define `result_a` with number of full weeks in a month
# 2. Define `result_b` with number of full weeks in a year
# 3. Run doctests - all must succeed
# %% Polish
# 1. Zdefiniuj `result_a` z liczbą pełnych tygodni w miesiącu
# 2. Zdefiniuj `result_b` z liczbą pełnych tygodni w roku
# 3. Uruchom doctesty - wszystkie muszą się powieść
# %% Expected
# >>> result_a
# 4
#
# >>> result_b
# 52
# %% Hints
# - `//` - floordiv operator
# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'
>>> assert result_a is not Ellipsis, \
'Variable `result_a` has an invalid value; assign result of your program to it.'
>>> assert type(result_a) is int, \
'Variable `result_a` has an invalid type; expected: `int`.'
>>> assert result_a == 4, \
'Variable `result_a` has invalid value. Check your calculation.'
>>> assert result_b is not Ellipsis, \
'Variable `result_b` has an invalid value; assign result of your program to it.'
>>> assert type(result_b) is int, \
'Variable `result_b` has an invalid type; expected: `int`.'
>>> assert result_b == 52, \
'Variable `result_b` has invalid value. Check your calculation.'
"""
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`
# %% Imports
# %% Types
result_a: int
result_b: int
# %% Data
DAY = 1
YEAR = 365*DAY
MONTH = 30*DAY
WEEK = 7*DAY
# %% Result
result_a = ...
result_b = ...
# %% About
# - Name: Numeric Int Floordiv
# - Difficulty: easy
# - Lines: 1
# - Minutes: 2
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% English
# 1. Image has dimensions 256x128 pixels
# 2. Screen resolution is 1920x1080 pixels
# 3. Define `result` with number of images you can display in one row
# 4. Run doctests - all must succeed
# %% Polish
# 1. Obrazek ma wymiary 256x128 pikseli
# 2. Rozdzielczość ekranu to 1920x1080 pikseli
# 3. Zdefiniuj `result` z liczbą obrazków, które można wyświetlić w jednym rzędzie
# 4. Uruchom doctesty - wszystkie muszą się powieść
# %% Expected
# >>> result
# 7
# %% Hints
# - `//` - floordiv operator
# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'
>>> assert result is not Ellipsis, \
'Variable `result` has an invalid value; assign result of your program to it.'
>>> assert type(result) is int, \
'Variable `result` has an invalid type; expected: `int`.'
>>> assert result == 7, \
'Variable `result` has invalid value. Check your calculation.'
"""
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`
# %% Imports
# %% Types
result: int
# %% Data
px = 1
IMG_WIDTH = 256*px
IMG_HEIGHT = 128*px
SCREEN_WIDTH = 1920*px
SCREEN_HEIGHT = 1080*px
# %% Result
result = ...
# %% About
# - Name: Numeric Int Constants
# - Difficulty: easy
# - Lines: 5
# - Minutes: 3
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% English
# 1. Define "constant" SECOND with value of 1 second
# 2. Define "constant" MINUTE with value of 1 minute (60 seconds)
# 3. Define "constant" HOUR with value of 1 hour (60 minutes)
# 4. Define "constant" DAY with value of 1 day (24 hours)
# 5. Define "constant" WEEK with value of 1 week (7 days)
# 6. All variables must be in seconds
# 7. Run doctests - all must succeed
# %% Polish
# 1. Zdefiniuj "stałą" SECOND z wartością dla 1 sekundy
# 2. Zdefiniuj "stałą" MINUTE z wartością dla 1 minuty (60 sekund)
# 3. Zdefiniuj "stałą" HOUR z wartością dla 1 godziny (60 minut)
# 4. Zdefiniuj "stałą" DAY z wartością dla 1 dzień (24 godziny)
# 5. Zdefiniuj "stałą" WEEK z wartością dla 1 tydzień (7 dni)
# 6. Wszystkie zmienne muszą być wyrażone w sekundach
# 7. Uruchom doctesty - wszystkie muszą się powieść
# %% Expected
# >>> SECOND
# 1
#
# >>> MINUTE
# 60
#
# >>> HOUR
# 3600
#
# >>> DAY
# 86400
#
# >>> WEEK
# 604800
# %% Hints
# - `*` - mul operator
# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'
>>> assert SECOND is not Ellipsis, \
'Variable `SECOND` has an invalid value; assign result of your program to it.'
>>> assert MINUTE is not Ellipsis, \
'Variable `MINUTE` has an invalid value; assign result of your program to it.'
>>> assert HOUR is not Ellipsis, \
'Variable `HOUR` has an invalid value; assign result of your program to it.'
>>> assert DAY is not Ellipsis, \
'Variable `DAY` has an invalid value; assign result of your program to it.'
>>> assert WEEK is not Ellipsis, \
'Variable `WEEK` has an invalid value; assign result of your program to it.'
>>> assert type(SECOND) is int, \
'Variable `SECOND` has an invalid type; expected: `int`.'
>>> assert type(MINUTE) is int, \
'Variable `MINUTE` has an invalid type; expected: `int`.'
>>> assert type(HOUR) is int, \
'Variable `HOUR` has an invalid type; expected: `int`.'
>>> assert type(DAY) is int, \
'Variable `DAY` has an invalid type; expected: `int`.'
>>> assert type(WEEK) is int, \
'Variable `WEEK` has an invalid type; expected: `int`.'
>>> assert SECOND == 1, \
'Variable `SECOND` has invalid value. Check your calculation.'
>>> assert MINUTE == 60, \
'Variable `MINUTE` has invalid value. Check your calculation.'
>>> assert HOUR == 3600, \
'Variable `HOUR` has invalid value. Check your calculation.'
>>> assert DAY == 86400, \
'Variable `DAY` has invalid value. Check your calculation.'
>>> assert WEEK == 604800, \
'Variable `WEEK` has invalid value. Check your calculation.'
"""
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`
# %% Imports
# %% Types
SECOND: int
MINUTE: int
HOUR: int
DAY: int
WEEK: int
# %% Data
# %% Result
SECOND = ...
MINUTE = ...
HOUR = ...
DAY = ...
WEEK = ...
# %% About
# - Name: Numeric Int Duration
# - Difficulty: easy
# - Lines: 5
# - Minutes: 3
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% English
# 1. Define variable `result_a` with value: 69 seconds
# 2. Define variable `result_b` with value: 13 minutes 37 seconds
# 3. Define variable `result_c` with value: 2 hours 56 minutes
# 4. Define variable `result_d` with value: 1 day 2 hours 8 minutes
# 5. Define variable `result_e` with value: 3 weeks 1 day 3 hours 3 minutes 7 seconds
# 6. All values must be in seconds
# 7. Run doctests - all must succeed
# %% Polish
# 1. Zdefiniuj zmienną `result_a` z wartością: 69 sekund
# 2. Zdefiniuj zmienną `result_b` z wartością: 13 minut 37 sekund
# 3. Zdefiniuj zmienną `result_c` z wartością: 2 godziny 56 minut
# 4. Zdefiniuj zmienną `result_d` z wartością: 1 dzień 2 godziny 8 minut
# 5. Zdefiniuj zmienną `result_e` z wartością: 3 tygodnie 1 dzień 3 godziny 3 minuty 7 sekund
# 6. Wszystkie zmienne muszą być wyrażone w sekundach
# 7. Uruchom doctesty - wszystkie muszą się powieść
# %% Expected
# >>> result_a
# 69
#
# >>> result_b
# 817
#
# >>> result_c
# 10560
#
# >>> result_d
# 94080
#
# >>> result_e
# 1911787
# %% Hints
# - `*` - mul operator
# - `+` - add
# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'
>>> assert result_a is not Ellipsis, \
'Variable `result_a` has an invalid value; assign result of your program to it.'
>>> assert result_b is not Ellipsis, \
'Variable `result_b` has an invalid value; assign result of your program to it.'
>>> assert result_c is not Ellipsis, \
'Variable `result_c` has an invalid value; assign result of your program to it.'
>>> assert result_d is not Ellipsis, \
'Variable `result_d` has an invalid value; assign result of your program to it.'
>>> assert result_e is not Ellipsis, \
'Variable `result_e` has an invalid value; assign result of your program to it.'
>>> assert type(result_a) is int, \
'Variable `result_a` has an invalid type; expected: `int`.'
>>> assert type(result_b) is int, \
'Variable `result_b` has an invalid type; expected: `int`.'
>>> assert type(result_c) is int, \
'Variable `result_c` has an invalid type; expected: `int`.'
>>> assert type(result_d) is int, \
'Variable `result_d` has an invalid type; expected: `int`.'
>>> assert type(result_e) is int, \
'Variable `result_e` has an invalid type; expected: `int`.'
>>> assert result_a == 69, \
'Variable `result_a` has invalid value. Check your calculation.'
>>> assert result_b == 817, \
'Variable `result_b` has invalid value. Check your calculation.'
>>> assert result_c == 10560, \
'Variable `result_c` has invalid value. Check your calculation.'
>>> assert result_d == 94080, \
'Variable `result_d` has invalid value. Check your calculation.'
>>> assert result_e == 1911787, \
'Variable `result_e` has invalid value. Check your calculation.'
"""
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`
# %% Imports
# %% Types
result_a: int
result_b: int
result_c: int
result_d: int
result_e: int
# %% Data
SECOND = 1
MINUTE = 60 * SECOND
HOUR = 60 * MINUTE
DAY = 24 * HOUR
WEEK = 7 * DAY
# %% Result
result_a = ...
result_b = ...
result_c = ...
result_d = ...
result_e = ...
# %% About
# - Name: Numeric Int Variables
# - Difficulty: easy
# - Lines: 4
# - Minutes: 3
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% English
# 1. Define variable `workbreak` with value: 5 minutes
# 2. Define variable `workday` with value: 8 workbreak
# 3. Define variable `workweek` with value: 5 workday
# 4. Define variable `workmonth` with value: 4 workweek
# 5. All variables must be in seconds
# 6. Run doctests - all must succeed
# %% Polish
# 1. Zdefiniuj zmienną `workbreak` z wartością: 5 minut
# 2. Zdefiniuj zmienną `workday` z wartością: 8 workbreak
# 3. Zdefiniuj zmienną `workweek` z wartością: 5 workday
# 4. Zdefiniuj zmienną `workmonth` z wartością: 4 workweek
# 5. Wszystkie zmienne muszą być wyrażone w sekundach
# 6. Uruchom doctesty - wszystkie muszą się powieść
# %% Expected
# >>> workbreak
# 300
#
# >>> workday
# 2400
#
# >>> workweek
# 12000
#
# >>> workmonth
# 48000
# %% Hints
# - `*` - mul operator
# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'
>>> from pprint import pprint
>>> assert workbreak is not Ellipsis, \
'Variable `workbreak` has an invalid value; assign result of your program to it.'
>>> assert workday is not Ellipsis, \
'Variable `workday` has an invalid value; assign result of your program to it.'
>>> assert workweek is not Ellipsis, \
'Variable `workweek` has an invalid value; assign result of your program to it.'
>>> assert workmonth is not Ellipsis, \
'Variable `workmonth` has an invalid value; assign result of your program to it.'
>>> assert type(workbreak) is int, \
'Variable `workbreak` has an invalid type; expected: `int`.'
>>> assert type(workday) is int, \
'Variable `workday` has an invalid type; expected: `int`.'
>>> assert type(workweek) is int, \
'Variable `workweek` has an invalid type; expected: `int`.'
>>> assert type(workmonth) is int, \
'Variable `workmonth` has an invalid type; expected: `int`.'
>>> pprint(workbreak)
300
>>> pprint(workday)
2400
>>> pprint(workweek)
12000
>>> pprint(workmonth)
48000
"""
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`
# %% Imports
# %% Types
workbreak: int
workday: int
workweek: int
workmonth: int
# %% Data
SECOND = 1
MINUTE = 60 * SECOND
HOUR = 60 * MINUTE
DAY = 24 * HOUR
WEEK = 7 * DAY
# %% Result
workbreak = ...
workday = ...
workweek = ...
workmonth = ...
# %% About
# - Name: Numeric Int Conversion
# - Difficulty: easy
# - Lines: 6
# - Minutes: 3
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% English
# 1. Define variable `day` with number of seconds in 24 hours
# 2. Define variable `week` with number of minutes in 7 days
# 3. Define variable `month` with number of hours in 31 days
# 4. Define variable `workday` with number of seconds in 8 hours
# 5. Define variable `workweek` with number of minutes in 5 work days
# 6. Define variable `workmonth` with number of hours in 22 work days
# 7. Use floordiv (`//`) operator
# 8. Run doctests - all must succeed
# %% Polish
# 1. Zdefiniuj zmienną `day` z liczbą sekund w ciągu 24 godzin
# 2. Zdefiniuj zmienną `week` z liczbą minut w ciągu 7 dni
# 3. Zdefiniuj zmienną `month` z liczbą godzin w ciągu 31 dni
# 4. Zdefiniuj zmienną `workday` z liczbą sekund w ciągu 8 godzin
# 5. Zdefiniuj zmienną `workweek` z liczbą minut w ciągu 5 dni pracy
# 6. Zdefiniuj zmienną `workmonth` z liczbą godzin w ciągu 22 dni pracy
# 7. Użyj operatora floordiv (`//`)
# 8. Uruchom doctesty - wszystkie muszą się powieść
# %% Expected
# >>> day
# 86400
#
# >>> week
# 10080
#
# >>> month
# 744
#
# >>> workday
# 28800
#
# >>> workweek
# 2400
#
# >>> workmonth
# 176
# %% Hints
# - `*` - mul operator
# - `//` - floordiv
# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'
>>> assert day is not Ellipsis, \
'Variable `day` has an invalid value; assign result of your program to it.'
>>> assert week is not Ellipsis, \
'Variable `week` has an invalid value; assign result of your program to it.'
>>> assert month is not Ellipsis, \
'Variable `month` has an invalid value; assign result of your program to it.'
>>> assert workday is not Ellipsis, \
'Variable `workday` has an invalid value; assign result of your program to it.'
>>> assert workweek is not Ellipsis, \
'Variable `workweek` has an invalid value; assign result of your program to it.'
>>> assert workmonth is not Ellipsis, \
'Variable `workmonth` has an invalid value; assign result of your program to it.'
>>> assert type(day) is int, \
'Variable `day` has an invalid type; expected: `int`.'
>>> assert type(week) is int, \
'Variable `week` has an invalid type; expected: `int`.'
>>> assert type(month) is int, \
'Variable `month` has an invalid type; expected: `int`.'
>>> assert type(workday) is int, \
'Variable `workday` has an invalid type; expected: `int`.'
>>> assert type(workweek) is int, \
'Variable `workweek` has an invalid type; expected: `int`.'
>>> assert type(workmonth) is int, \
'Variable `workmonth` has an invalid type; expected: `int`.'
>>> assert day == 86400, \
'Variable `day` has invalid value. Check your calculation.'
>>> assert week == 10080, \
'Variable `week` has invalid value. Check your calculation.'
>>> assert month == 744, \
'Variable `month` has invalid value. Check your calculation.'
>>> assert workday == 28800, \
'Variable `workday` has invalid value. Check your calculation.'
>>> assert workweek == 2400, \
'Variable `workweek` has invalid value. Check your calculation.'
>>> assert workmonth == 176, \
'Variable `workmonth` has invalid value. Check your calculation.'
"""
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`
# %% Imports
# %% Types
day: int
week: int
month: int
workday: int
workweek: int
workmonth: int
# %% Data
SECOND = 1
MINUTE = 60 * SECOND
HOUR = 60 * MINUTE
DAY = 24 * HOUR
WEEK = 7 * DAY
# %% Result
day = ...
week = ...
month = ...
workday = ...
workweek = ...
workmonth = ...
# %% About
# - Name: Numeric Int Bits
# - Difficulty: medium
# - Lines: 3
# - Minutes: 3
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% English
# 1. File size `SIZE` is 1337 megabits [Mb]
# 2. Define variable `size_bits` with `SIZE` in bits [b]
# 3. Define variable `size_kilobits` with `SIZE` in kilobits [kb]
# 4. Define variable `size_megabits` with `SIZE` in megabits [Mb]
# 5. Use floordiv (`//`) operator
# 6. Run doctests - all must succeed
# %% Polish
# 1. Wielkość pliku `SIZE` to 1337 megabits [Mb]
# 2. Zdefiniuj zmienną `size_bits` z rozmiarem `SIZE` w bitach [b]
# 3. Zdefiniuj zmienną `size_kilobits` z rozmiarem `SIZE` w kilobitach [kb]
# 4. Zdefiniuj zmienną `size_megabits` z rozmiarem `SIZE` w megabitach [Mb]
# 5. Użyj operatora floordiv (`//`)
# 6. Uruchom doctesty - wszystkie muszą się powieść
# %% Expected
# >>> size_bits
# 1_401_946_112
#
# >>> size_kilobits
# 1_369_088
#
# >>> size_megabits
# 1337
# %% Hints
# - `//` - floordiv
# - 1 kb = 1024 b
# - 1 Mb = 1024 Kb
# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'
>>> assert size_bits is not Ellipsis, \
'Variable `size_bits` has an invalid value; assign result of your program to it.'
>>> assert size_kilobits is not Ellipsis, \
'Variable `size_kilobits` has an invalid value; assign result of your program to it.'
>>> assert size_megabits is not Ellipsis, \
'Variable `size_megabits` has an invalid value; assign result of your program to it.'
>>> assert type(size_bits) is int, \
'Variable `size_bits` has an invalid type; expected: `int`.'
>>> assert type(size_kilobits) is int, \
'Variable `size_kilobits` has an invalid type; expected: `int`.'
>>> assert type(size_megabits) is int, \
'Variable `size_megabits` has an invalid type; expected: `int`.'
>>> assert size_bits == 1_401_946_112, \
'Invalid value for `size_bits`. Check you calculation'
>>> assert size_kilobits == 1_369_088, \
'Invalid value for `size_kilobits`. Check you calculation'
>>> assert size_megabits == 1337, \
'Invalid value for `size_megabits`. Check you calculation'
"""
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`
# %% Imports
# %% Types
size_bits: int
size_kilobits: int
size_megabits: int
# %% Data
b = 1
kb = 1024 * b
Mb = 1024 * kb
SIZE = 1337 * Mb
# %% Result
size_bits = ...
size_kilobits = ...
size_megabits = ...
# %% About
# - Name: Numeric Int Bytes
# - Difficulty: medium
# - Lines: 2
# - Minutes: 2
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% English
# 1. File size `SIZE` is 100 megabytes [MB]
# 2. Define variable `size_kilobytes` with size `SIZE` in kilobytes [kB]
# 3. Define variable `size_megabits` with size `SIZE` in megabits [Mb]
# 4. Run doctests - all must succeed
# %% Polish
# 1. Wielkość pliku `SIZE` to 100 megabajtów [MB]
# 2. Zdefiniuj zmienną `size_kilobytes` z rozmiarem `SIZE` w kilobajtach [kB]
# 3. Zdefiniuj zmienną `size_megabits` z rozmiarem `SIZE` w megabitach [Mb]
# 4. Uruchom doctesty - wszystkie muszą się powieść
# %% Expected
# >>> size_kilobytes
# 102_400
#
# >>> size_megabits
# 800
# %% Hints
# - `//` - floordiv
# - 1 Kb = 1024 b
# - 1 Mb = 1024 Kb
# - 1 B = 8 b
# - 1 KB = 1024 B
# - 1 MB = 1024 KB
# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'
>>> assert size_kilobytes is not Ellipsis, \
'Variable `size_kilobytes` has an invalid value; assign result of your program to it.'
>>> assert size_megabits is not Ellipsis, \
'Variable `size_megabits` has an invalid value; assign result of your program to it.'
>>> assert type(size_kilobytes) is int, \
'Variable `size_kilobytes` has an invalid type; expected: `int`.'
>>> assert type(size_megabits) is int, \
'Variable `size_megabits` has an invalid type; expected: `int`.'
>>> assert size_kilobytes == 102_400, \
'Invalid value for `size_kilobytes`. Check you calculation'
>>> assert size_megabits == 800, \
'Invalid value for `size_megabits`. Check you calculation'
"""
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`
# %% Imports
# %% Types
size_kilobytes: int
size_megabits: int
# %% Data
b = 1
kb = 1024 * b
Mb = 1024 * kb
B = 8 * b
kB = 1024 * B
MB = 1024 * kB
SIZE = 100 * MB
# %% Result
size_kilobytes = ...
size_megabits = ...
# %% About
# - Name: Numeric Int Bandwidth
# - Difficulty: medium
# - Lines: 3
# - Minutes: 3
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% English
# 1. Having internet connection with speed (`bandwidth`) 100 Mb/s
# 2. How long will take to download (`size`) 100 MB?
# 3. To calculate time divide file size by bandwidth and type cast to `int`
# 4. Define variable `duration` with the solution in seconds
# 5. Use floordiv (`//`) operator
# 6. Run doctests - all must succeed
# %% Polish
# 1. Mając łącze internetowe (`bandwidth`) 100 Mb/s
# 2. Ile zajmie ściągnięcie pliku (`size`) 100 MB?
# 3. Aby wyliczyć czas podziel wielkość pliku przez prędkość i rzutuj na `int`
# 4. Zdefiniuj zmienną `duration` z rozwiązaniem w sekundach
# 5. Użyj operatora floordiv (`//`)
# 6. Uruchom doctesty - wszystkie muszą się powieść
# %% Expected
# >>> bandwidth
# 104_857_600
#
# >>> size
# 838_860_800
#
# >>> duration
# 8
# %% Hints
# - `*` - mul operator
# - `//` - floordiv
# - 1 Kb = 1024 b
# - 1 Mb = 1024 Kb
# - 1 B = 8 b
# - 1 KB = 1024 B
# - 1 MB = 1024 KB
# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'
>>> assert bandwidth is not Ellipsis, \
'Variable `bandwidth` has an invalid value; assign result of your program to it.'
>>> assert size is not Ellipsis, \
'Variable `size` has an invalid value; assign result of your program to it.'
>>> assert duration is not Ellipsis, \
'Variable `duration` has an invalid value; assign result of your program to it.'
>>> assert type(bandwidth) is int, \
'Variable `bandwidth` has an invalid type; expected: `int`.'
>>> assert type(size) is int, \
'Variable `size` has an invalid type; expected: `int`.'
>>> assert type(duration) is int, \
'Variable `duration` has an invalid type; expected: `int`.'
>>> assert bandwidth == 104_857_600, \
'Variable `bandwidth` has an invalid value; expected: `104_857_600`.'
>>> assert size == 838_860_800, \
'Variable `size` has an invalid value; expected: `838_860_800`.'
>>> assert duration == 8, \
'Variable `duration` has an invalid value; expected: `8`.'
"""
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`
# %% Imports
# %% Types
bandwidth: int
size: int
duration: int
# %% Data
SECOND = 1
b = 1
kb = 1024 * b
Mb = 1024 * kb
B = 8 * b
kB = 1024 * B
MB = 1024 * kB
# %% Result
bandwidth = ...
size = ...
duration = ...