# 3.1. Type int

## 3.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 11. int Type Definition
value = 30              # 30
value = -30             # -30

million = 1000000        # 1000000
million = 1_000_000      # 1000000


## 3.1.2. Type Casting

• int() converts argument to int

• int() does not round numbers, it returns integer value

Listing 12. int() converts argument to int
int(10)                     # 10
int(10.0)                   # 10
int(10.9)                   # 10
int(13.37)                  # 13
int(-13.37)                 # -13
int('1')                    # 1
int('-1')                   # -1
int('13.37')                # ValueError: invalid literal for int() with base 10: '1.23'
int('-13.37')               # ValueError: invalid literal for int() with base 10: '-1.23'


## 3.1.3. Assignments

### 3.1.3.1. Example

English
1. Calculate how many bits is one Megabyte

2. How many times Megabyte is larger than Megabit?

Polish
1. Oblicz ile bitów to jeden Megabajt

2. Ile razy Megabajt jest większy od Megabita?

Solution
BIT = 1
KILOBIT = 1024 * BIT
MEGABIT = 1024 * KILOBIT

BYTE = 8 * BIT
KILOBYTE = 1024 * BYTE
MEGABYTE = 1024 * KILOBYTE

print(f'1 MB in bit = {1*MEGABYTE / BIT}')
print(f'1 MB in Mb = {1*MEGABYTE / MEGABIT} Mb')
print(f'MB - Mb = {(MEGABYTE - MEGABIT) / BIT}')

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

### 3.1.3.2. Int Calculation

• Complexity level: easy

• Lines of code to write: 12 lines

• Estimated time of completion: 5 min

English
1. Calculate how many seconds is five minutes

2. Calculate how many seconds is one hour

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

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

5. Calculate how many minutes is work week (40 hours)

Polish
1. Oblicz ile sekund to pięć minut

2. Oblicz ile sekund to jedna godzina

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

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

5. Oblicz ile minut to tydzień pracy (40 godzin)

The whys and wherefores
• Defining constants and variables

• Naming convention

• Mathematical operations

Hint
• 1 h = 60 min

• 1 min = 60 s

### 3.1.3.3. Int Ratio

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

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

### 3.1.3.4. Int Temperature

• Complexity level: medium

• Lines of code to write: 18 lines

• Estimated time of completion: 15 min

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: 180 °C

• Lunar night: 93 K

• Mars average: −63 °C

• Mars highest: 20 °C

• Mars lowest: 120 K

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ń: 180 °C

• Księżyca w nocy: 93 K

• Mars średnia: −63 °C

• Mars najwyższa: 20 °C

• Mars najniższa: 120 K

The whys and wherefores
• Defining constants and variables

• Naming convention

• Print formatting

• Mathematical operations