2.1. Type Int

2.1.1. Type Definition

  • In Python 3 there is not maximal int value

  • Python 3 dynamically extends int, when it's too big

  • You can use _ for easier read especially with big numbers

Listing 2.1. int Type Definition
data = 1337                 # 1337
data = -1337                # -1337
million = 1000000           # 1000000
million = 1_000_000         # 1000000

2.1.2. Type Casting

  • int() - converts argument to int

  • int() - does not round numbers

Listing 2.2. int() converts argument to int
int(13)                     # 13
int(13.0)                   # 13
int(13.3)                   # 13
int(13.37)                  # 13

int(-13.37)                 # -13

int('1')                    # 1
int('+1')                   # 1
int('-1')                   # -1
int('1_000_000')            # 1000000

int('13.37')                # ValueError: invalid literal for int() with base 10: '13.37'
int('13,37')                # ValueError: invalid literal for int() with base 10: '13,37'
int('-13.37')               # ValueError: invalid literal for int() with base 10: '-13.37'
int('-13,37')               # ValueError: invalid literal for int() with base 10: '-13,37'

2.1.3. Type Checking

  • type() - Returns type of an argument

type(1)                     # <class 'int'>
type(-1)                    # <class 'int'>
type(0)                     # <class 'int'>
type(-0)                    # <class 'int'>

2.1.4. Assignments

2.1.4.1. Type Int Time

  • Complexity level: easy

  • Lines of code to write: 12 lines

  • Estimated time of completion: 5 min

  • Solution: solution/type_int_time.py

English
  1. Calculate how many seconds is one day

  2. Calculate how many minutes is one day

  3. Calculate how many seconds is work day (8 hours)

  4. Calculate how many hours is work month (22 work days)

  5. Calculate how many minutes is work week (5 work days)

Polish
  1. Oblicz ile sekund to jedna doba

  2. Oblicz ile minut to je jedna doba

  3. Oblicz ile sekund to dzień pracy (8 godzin)

  4. Oblicz ile godzin to miesiąc pracy (22 dni pracy)

  5. Oblicz ile minut to tydzień pracy (5 dni pracy)

The whys and wherefores
  • Defining constants and variables

  • Naming convention

  • Mathematical operations

Hint
  • 1 h = 60 min

  • 1 min = 60 s

2.1.4.2. Type Int Bytes

  • Complexity level: medium

  • Lines of code to write: 9 lines

  • Estimated time of completion: 3 min

  • Solution: solution/type_int_bytes.py

English
  1. File size is one megabyte

  2. Calculate size in bits

  3. Calculate size in megabits

Polish
  1. Wielkość pliku to jeden megabajt

  2. Oblicz wielkość w bitach

  3. Oblicz wielkość w megabitach

The whys and wherefores
  • Defining constants and variables

  • Naming convention

  • Mathematical operations

Hint
  • 1 Kb = 1024 b

  • 1 Mb = 1024 Kb

  • 1 B = 8 b

  • 1 KB = 1024 B

  • 1 MB = 1024 KB

2.1.4.3. Type Int Bandwidth

English
  1. Having internet connection with speed up to 100 Mb/s

  2. How long will take to download 100 MB?

Polish
  1. Mając łącze internetowe "do 100 Mb/s"

  2. Ile zajmie ściągnięcie pliku 100 MB?

The whys and wherefores
  • Defining constants and variables

  • Naming convention

  • Mathematical operations

Hint
  • 1 Kb = 1024 b

  • 1 Mb = 1024 Kb

  • 1 B = 8 b

  • 1 KB = 1024 B

  • 1 MB = 1024 KB

2.1.4.4. Type Int Temperature

English
  1. One Kelvin is equal to 1 Celsius degree (1K = 1°C)

  2. Zero Kelvin (absolute) is equal to -273.15 Celsius degrees

  3. For calculation use round number -273 (0K = -273°C)

  4. How many Kelvins and Celsius degrees has average temperatures at surface [dACSICINTA19]:

    • Lunar day: 453 K

    • Lunar night: 93 K

    • Mars highest: 20 °C

    • Mars lowest: -153 °C

    • Mars average: −63 °C

Polish
  1. Jeden Kelwin to jeden stopień Celsiusza (1K = 1°C)

  2. Zero Kelwina (bezwzględne) to -273.15 stopni Celsiusza

  3. W zadaniu przyjmij równe -273°C (0K = -273°C)

  4. Ile Kelwinów, a ile stopni Celsiusza wynoszą średnie temperatury powierzchni [dACSICINTA19]:

    • Księżyca w dzień: 453 K

    • Księżyca w nocy: 93 K

    • Mars najwyższa: 20 °C

    • Mars najniższa: -153 °C

    • Mars średnia: −63 °C

The whys and wherefores
  • Defining constants and variables

  • Naming convention

  • Print formatting

  • Mathematical operations