3.1. Numeric Int¶
Represents integer
Could be both signed and unsigned
There is no maximal or minimal
int
valueDefault
int
size is 64 bitPython automatically extends
int
when need bigger number
3.1.1. Syntax¶
Signed and Unsigned
Use
_
for thousand separator
>>> data = 1
>>> data = +1
>>> data = -1
You can use _
for easier read especially with big numbers:
>>> million = 1000000
>>> million = 1_000_000
>>>
>>> print(million)
1000000
3.1.2. Type Conversion¶
Builtin function
int()
converts argument toint
It is not rounding
Works with strings, if all characters could be converted to
int
Supports only:
+
,-
and_
(underscore)
Builtin function int()
converts argument to int
:
>>> int(1)
1
>>>
>>> int(+1)
1
>>>
>>> int(-1)
-1
>>> int(1.337)
1
>>>
>>> int(+1.1337)
1
>>>
>>> int(-1.337)
-1
>>> int('1')
1
>>>
>>> int('+1')
1
>>>
>>> int('-1')
-1
>>> int('1_000_000')
1000000
>>>
>>> int('-1_000_000')
-1000000
3.1.3. Type Conversion Errors¶
Works with strings, if all characters could be converted to
int
It is not validator or parser to extract all numbers from
str
Builtin function int()
fails when in argument there are parameters
other than a digit, +
or -
sign and _
>>> int('3.1337')
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: '3.1337'
>>> int('+3.1337')
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: '+3.1337'
>>> int('-3.1337')
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: '-3.1337'
>>> int('3,1337')
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: '3,1337'
>>> int('+3,1337')
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: '+3,1337'
>>> int('-3,1337')
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: '-3,1337'
3.1.4. Rounding¶
Builtin function
int()
does not round numbers - only converts toint
Use
round()
for numbers rounding
Builtin function int()
does not round numbers:
>>> int(1.11)
1
>>>
>>> int(1.99)
1
Builtin function round()
does that:
>>> round(1.11)
1
>>>
>>> round(1.99)
2
3.1.5. Absolute Value¶
abs()
- Absolute value
>>> abs(1)
1
>>>
>>> abs(-1)
1
>>> abs(+0)
0
>>> abs(-0)
0
3.1.6. Use Case - 0x01¶
>>> 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.7. Use Case - 0x02¶
>>> m = 1
>>> km = 1000 * m
>>> mi = 1652 * m
>>>
>>>
>>> distance = 123*mi
>>>
>>> distance // m
203196
>>> distance // km
203
3.1.8. Use Case - 0x03¶
>>> 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.9. Assignments¶
"""
* Assignment: Type Int Time
* Type: class assignment
* Complexity: easy
* Lines of code: 5 lines
* Time: 3 min
English:
1. Define variables for:
a. second: 1 second
b: minute: 60 seconds
c. hour: 60 minutes
d. day: 24 hours
e. week: 7 days
2. All variables must be in seconds
3. Run doctests - all must succeed
Polish:
1. Zdefiniuj zmienne dla:
a. second: 1 sekunda
b: minute: 60 sekund
c. hour: 60 minut
d. day: 24 godzin
e. week: 7 dni
2. Wszystkie zmienne muszą być wyrażone w sekundach
3. Uruchom doctesty - wszystkie muszą się powieść
Hints:
* Multiply
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> assert second is not Ellipsis, \
'Assign your result to variable `second`'
>>> assert minute is not Ellipsis, \
'Assign your result to variable `minute`'
>>> assert hour is not Ellipsis, \
'Assign your result to variable `hour`'
>>> assert day is not Ellipsis, \
'Assign your result to variable `day`'
>>> assert week is not Ellipsis, \
'Assign your result to variable `week`'
>>> assert type(second) is int, \
'Variable `second` has invalid type, should be int'
>>> assert type(minute) is int, \
'Variable `minute` has invalid type, should be int'
>>> assert type(hour) is int, \
'Variable `hour` has invalid type, should be int'
>>> assert type(day) is int, \
'Variable `day` has invalid type, should be int'
>>> assert type(week) is int, \
'Variable `week` has invalid type, should be 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.'
"""
# second: 1 second
# type: int
second = ...
# minute: 60 seconds
# type: int
minute = ...
# hour: 60 minutes
# type: int
hour = ...
# day: 24 hours
# type: int
day = ...
# week: 7 days
# type: int
week = ...
"""
* Assignment: Type Int Time
* Type: class assignment
* Complexity: easy
* Lines of code: 5 lines
* Time: 3 min
English:
1. Define variables for:
a. result_a: 69 seconds
b. result_b: 13 minutes 37 seconds
c. result_c: 2 hours 56 minutes
d. result_d: 1 day 2 hours 8 minutes
e. result_e: 3 weeks 1 day 3 hours 3 minutes 7 seconds
2. All variables must be in seconds
3. Run doctests - all must succeed
Polish:
1. Zdefiniuj zmienne dla:
a. result_a: 69 sekunda
b. result_b: 13 minut 37 sekund
c. result_c: 2 godziny 56 minut
d. result_d: 1 dzień 2 godziny 8 minut
e. result_e: 3 tygodnie 1 dzień 3 godziny 3 minuty 7 sekund
2. Wszystkie zmienne muszą być wyrażone w sekundach
3. Uruchom doctesty - wszystkie muszą się powieść
Hints:
* Multiply
* Add
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> assert result_a is not Ellipsis, \
'Assign your result to variable `result_a`'
>>> assert result_b is not Ellipsis, \
'Assign your result to variable `result_b`'
>>> assert result_c is not Ellipsis, \
'Assign your result to variable `result_c`'
>>> assert result_d is not Ellipsis, \
'Assign your result to variable `result_d`'
>>> assert result_e is not Ellipsis, \
'Assign your result to variable `result_e`'
>>> assert type(result_a) is int, \
'Variable `result_a` has invalid type, should be int'
>>> assert type(result_b) is int, \
'Variable `result_b` has invalid type, should be int'
>>> assert type(result_c) is int, \
'Variable `result_c` has invalid type, should be int'
>>> assert type(result_d) is int, \
'Variable `result_d` has invalid type, should be int'
>>> assert type(result_e) is int, \
'Variable `result_e` has invalid type, should be 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.'
"""
SECOND = 1
MINUTE = 60 * SECOND
HOUR = 60 * MINUTE
DAY = 24 * HOUR
WEEK = 7 * DAY
# 69 seconds
# type: int
result_a = ...
# 13 minutes 37 seconds
# type: int
result_b = ...
# 2 hours 56 minutes
# type: int
result_c = ...
# 1 day 2 hours 8 minutes
# type: int
result_d = ...
# 3 weeks 1 day 3 hours 3 minutes 7 seconds
# type: int
result_e = ...
"""
* Assignment: Type Int Time
* Type: class assignment
* Complexity: easy
* Lines of code: 4 lines
* Time: 3 min
English:
1. Define variables for breaks in work:
a. workbreak: 5 minutes
b. workday: 8 workbreak
c. workweek: 5 workday
d. workmonth: 4 workweek
2. All variables must be in seconds
3. Run doctests - all must succeed
Polish:
1. Zdefiniuj zmienne dla przerw w pracy:
a. workbreak: 5 minut
b. workday: 8 workbreak
c. workweek: 5 workday
d. workmonth: 4 workweek
2. Wszystkie zmienne muszą być wyrażone w sekundach
3. Uruchom doctesty - wszystkie muszą się powieść
Hints:
* Multiply
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> from pprint import pprint
>>> assert workbreak is not Ellipsis, \
'Assign your result to variable `workbreak`'
>>> assert workday is not Ellipsis, \
'Assign your result to variable `workday`'
>>> assert workweek is not Ellipsis, \
'Assign your result to variable `workweek`'
>>> assert workmonth is not Ellipsis, \
'Assign your result to variable `workmonth`'
>>> assert type(workbreak) is int, \
'Variable `workbreak` has invalid type, should be int'
>>> assert type(workday) is int, \
'Variable `workday` has invalid type, should be int'
>>> assert type(workweek) is int, \
'Variable `workweek` has invalid type, should be int'
>>> assert type(workmonth) is int, \
'Variable `workmonth` has invalid type, should be int'
>>> pprint(workbreak)
300
>>> pprint(workday)
2400
>>> pprint(workweek)
12000
>>> pprint(workmonth)
48000
"""
SECOND = 1
MINUTE = 60 * SECOND
HOUR = 60 * MINUTE
DAY = 24 * HOUR
WEEK = 7 * DAY
# workbreak: 5 minutes
# type: int
workbreak = ...
# workday: 8 workbreak
# type: int
workday = ...
# workweek: 5 workday
# type: int
workweek = ...
# workmonth: 4 workweek
# type: int
workmonth = ...
"""
* Assignment: Type Int Time
* Type: class assignment
* Complexity: easy
* Lines of code: 6 lines
* Time: 3 min
English:
1. Calculate how many seconds is one day (24 hours)
2. Calculate how many minutes is one week (7 days)
3. Calculate how many hours is in one month (31 days)
4. Calculate how many seconds is work day (8 hours)
5. Calculate how many minutes is work week (5 work days)
6. Calculate how many hours is work month (22 work days)
7. Use floordiv (`//`) operator
8. Run doctests - all must succeed
Polish:
1. Oblicz ile sekund to jedna doba (24 godziny)
2. Oblicz ile minut to jeden tydzień (7 dni)
3. Oblicz ile godzin to jeden miesiąc (31 dni)
4. Oblicz ile sekund to dzień pracy (8 godzin)
5. Oblicz ile minut to tydzień pracy (5 dni pracy)
6. Oblicz ile godzin to miesiąc pracy (22 dni pracy)
7. Użyj operatora floordiv (`//`)
8. Uruchom doctesty - wszystkie muszą się powieść
Hints:
* Multiply
* Divide (floordiv)
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> assert day is not Ellipsis, \
'Assign your result to variable `day`'
>>> assert week is not Ellipsis, \
'Assign your result to variable `week`'
>>> assert month is not Ellipsis, \
'Assign your result to variable `month`'
>>> assert workday is not Ellipsis, \
'Assign your result to variable `workday`'
>>> assert workweek is not Ellipsis, \
'Assign your result to variable `workweek`'
>>> assert workmonth is not Ellipsis, \
'Assign your result to variable `workmonth`'
>>> assert type(day) is int, \
'Variable `day` has invalid type, should be int'
>>> assert type(week) is int, \
'Variable `week` has invalid type, should be int'
>>> assert type(month) is int, \
'Variable `month` has invalid type, should be int'
>>> assert type(workday) is int, \
'Variable `workday` has invalid type, should be int'
>>> assert type(workweek) is int, \
'Variable `workweek` has invalid type, should be int'
>>> assert type(workmonth) is int, \
'Variable `workmonth` has invalid type, should be 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.'
"""
SECOND = 1
MINUTE = 60 * SECOND
HOUR = 60 * MINUTE
DAY = 24 * HOUR
# 1 day in seconds
# Use floordiv (`//`) operator
# type: int
day = ...
# 7 days in minutes
# Use floordiv (`//`) operator
# type: int
week = ...
# 31 days in hours
# Use floordiv (`//`) operator
# type: int
month = ...
# 8 hours in seconds
# Use floordiv (`//`) operator
# type: int
workday = ...
# 5 workdays in minutes
# Use floordiv (`//`) operator
# type: int
workweek = ...
# 22 workdays in hours
# Use floordiv (`//`) operator
# type: int
workmonth = ...
"""
* Assignment: Type Int Add
* Type: class assignment
* Complexity: easy
* Lines of code: 3 lines
* Time: 3 min
English:
1. Define average temperatures at surface of Mars [1]:
a. highest: 20 °C
b. lowest: -153 °C
c. average: −63 °C
2. Run doctests - all must succeed
Polish:
1. Zdefiniuj średnie temperatury powierzchni Marsa [1]:
a. najwyższa: 20 °C
b. najniższa: -153 °C
c. średnia: −63 °C
2. Uruchom doctesty - wszystkie muszą się powieść
Hints:
* Multiply
References:
[1] Centro de Astrobiología (CSIC-INTA).
Rover Environmental Monitoring Station, Mars Science Laboratory (NASA).
Year: 2019.
Retrieved: 2019-08-06.
URL: http://cab.inta-csic.es/rems/marsweather.html
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> assert mars_highest is not Ellipsis, \
'Assign your result to variable `mars_highest`'
>>> assert mars_lowest is not Ellipsis, \
'Assign your result to variable `mars_lowest`'
>>> assert mars_lowest is not Ellipsis, \
'Assign your result to variable `mars_lowest`'
>>> assert type(mars_highest) is int, \
'Variable `mars_highest` has invalid type, should be int'
>>> assert type(mars_lowest) is int, \
'Variable `mars_lowest` has invalid type, should be int'
>>> assert type(mars_lowest) is int, \
'Variable `mars_average` has invalid type, should be int'
>>> assert mars_highest == 20, \
'Invalid value for `mars_highest`, should be 20. Check you calculation'
>>> assert mars_lowest == -153, \
'Invalid value for `mars_lowest`, should be -153. Check you calculation'
>>> assert mars_average == -63, \
'Invalid value for `mars_average`, should be -63. Check you calculation'
"""
Celsius = 1
# Martian highest temperature: 20 Celsius
# type: int
mars_highest = ...
# Martian lowest temperature: -153 Celsius
# type: int
mars_lowest = ...
# Martian average temperature: -63 Celsius
# type: int
mars_average = ...
"""
* Assignment: Type Int Add
* Type: class assignment
* Complexity: easy
* Lines of code: 3 lines
* Time: 3 min
English:
1. One Kelvin is equal to 1 Celsius degree (1K = 1°C)
2. Zero Celsius degrees is equal to 273.15 Kelvins
3. For calculation use round number 273 (0°C = 273K)
4. How many Kelvins has average temperatures at surface [1]:
a. Mars highest: 20 °C
b. Mars lowest: -153 °C
c. Mars average: −63 °C
5. Run doctests - all must succeed
Polish:
1. Jeden Kelwin to jeden stopień Celsiusza (1K = 1°C)
2. Zero stopni Celsiusza to 273.15 Kelwiny
3. W zadaniu przyjmij równe 273°C (0°C = 273K)
4. Ile Kelwinów wynoszą średnie temperatury powierzchni [1]:
a. Mars najwyższa: 20 °C
b. Mars najniższa: -153 °C
c. Mars średnia: −63 °C
5. Uruchom doctesty - wszystkie muszą się powieść
Hint:
* Add
References:
[1] Centro de Astrobiología (CSIC-INTA).
Rover Environmental Monitoring Station, Mars Science Laboratory (NASA).
Year: 2019.
Retrieved: 2019-08-06.
URL: http://cab.inta-csic.es/rems/marsweather.html
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> assert mars_highest is not Ellipsis, \
'Assign your result to variable `mars_highest`'
>>> assert mars_lowest is not Ellipsis, \
'Assign your result to variable `mars_lowest`'
>>> assert mars_lowest is not Ellipsis, \
'Assign your result to variable `mars_lowest`'
>>> assert type(mars_highest) is int, \
'Variable `mars_highest` has invalid type, should be int'
>>> assert type(mars_lowest) is int, \
'Variable `mars_lowest` has invalid type, should be int'
>>> assert type(mars_lowest) is int, \
'Variable `mars_average` has invalid type, should be int'
>>> assert mars_highest == 293, \
'Invalid value for `mars_highest`, should be 293. Check you calculation'
>>> assert mars_lowest == 120, \
'Invalid value for `mars_lowest`, should be 120. Check you calculation'
>>> assert mars_average == 210, \
'Invalid value for `mars_average`, should be 210. Check you calculation'
"""
Celsius = 1
Kelvin = 273
MARS_HIGHEST = 20*Celsius
MARS_LOWEST = -153*Celsius
MARS_AVERAGE = -63*Celsius
# Martian highest temperature: 20 Celsius in Kelvin
# type: int
mars_highest = ...
# Martian lowest temperature: -153 Celsius in Kelvin
# type: int
mars_lowest = ...
# Martian average temperature: -63 Celsius in Kelvin
# type: int
mars_average = ...
"""
* Assignment: Type Int Sub
* Type: class assignment
* Complexity: easy
* Lines of code: 2 lines
* Time: 2 min
English:
1. Define average temperatures at surface of Moon [1]:
a. day: 453 K
b. night: 93 K
2. Run doctests - all must succeed
Polish:
1. Zdefiniuj średnie temperatury powierzchni Księżyca [1]:
a. dzień: 453 K
b. noc: 93 K
2. Uruchom doctesty - wszystkie muszą się powieść
Hints:
* Multiply
References:
[1] Centro de Astrobiología (CSIC-INTA).
Rover Environmental Monitoring Station, Mars Science Laboratory (NASA).
Year: 2019.
Retrieved: 2019-08-06.
URL: http://cab.inta-csic.es/rems/marsweather.html
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> assert lunar_day is not Ellipsis, \
'Assign your result to variable `lunar_day`'
>>> assert lunar_night is not Ellipsis, \
'Assign your result to variable `lunar_night`'
>>> assert type(lunar_day) is int, \
'Variable `lunar_day` has invalid type, should be int'
>>> assert type(lunar_night) is int, \
'Variable `lunar_night` has invalid type, should be int'
>>> assert lunar_day == 453, \
'Invalid value for `lunar_day`, should be 453. Check you calculation'
>>> assert lunar_night == 93, \
'Invalid value for `lunar_night`, should be 93. Check you calculation'
"""
Kelvin = 1
# Lunar day: 453 Kelvins
# type: int
lunar_day = ...
# Lunar night: 93 Kelvins
# type: int
lunar_night = ...
"""
* Assignment: Type Int Sub
* Type: class assignment
* Complexity: easy
* Lines of code: 2 lines
* Time: 2 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 Celsius degrees has average temperatures at surface [1]:
a. Lunar day: 453 K
b. Lunar night: 93 K
5. Run doctests - all must succeed
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 stopni Celsiusza wynoszą średnie temperatury powierzchni [1]:
a. Księżyca w dzień: 453 K
b. Księżyca w nocy: 93 K
5. Uruchom doctesty - wszystkie muszą się powieść
Hint:
* Subtract
References:
[1] Centro de Astrobiología (CSIC-INTA).
Rover Environmental Monitoring Station, Mars Science Laboratory (NASA).
Year: 2019.
Retrieved: 2019-08-06.
URL: http://cab.inta-csic.es/rems/marsweather.html
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> assert lunar_day is not Ellipsis, \
'Assign your result to variable `lunar_day`'
>>> assert lunar_night is not Ellipsis, \
'Assign your result to variable `lunar_night`'
>>> assert type(lunar_day) is int, \
'Variable `lunar_day` has invalid type, should be int'
>>> assert type(lunar_night) is int, \
'Variable `lunar_night` has invalid type, should be int'
>>> assert lunar_day == 180, \
'Invalid value for `lunar_day`, should be 180. Check you calculation'
>>> assert lunar_night == -180, \
'Invalid value for `lunar_night`, should be -180. Check you calculation'
"""
Celsius = 273
Kelvin = 1
LUNAR_DAY = 453*Kelvin
LUNAR_NIGHT = 93*Kelvin
# Lunar day: 453 Kelvin in Celsius
# type: int
lunar_day = ...
# Lunar night: 93 Kelvin in Celsius
# type: int
lunar_night = ...
"""
* Assignment: Type Int Mul
* Type: class assignment
* Complexity: easy
* Lines of code: 3 lines
* Time: 3 min
English:
1. Define altitude in kilometers:
a. Armstrong Limit: 19 km
b. Stratosphere: 20 km
c. USAF Space Line: 80 km
d. IAF Space Line: 100 km
2. Run doctests - all must succeed
Polish:
1. Zdefiniuj wysokości w kilometrach:
a. Linia Armstronga: 19 km
b. Stratosfera: 20 km
c. Granica kosmosu wg. USAF: 80 km
d. Granica kosmosu wg. IAF 100 km
2. Uruchom doctesty - wszystkie muszą się powieść
Hints:
* Multiply
References:
* USAF - United States Air Force
* IAF - International Astronautical Federation
* Kármán line (100 km) - boundary between Earth's atmosphere and space
* Armstrong limit (19 km) - altitude above which atmospheric pressure is
sufficiently low that water boils at the temperature of the human body
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> assert armstrong_limit is not Ellipsis, \
'Assign your result to variable `armstrong_limit`'
>>> assert stratosphere is not Ellipsis, \
'Assign your result to variable `stratosphere`'
>>> assert usaf_space is not Ellipsis, \
'Assign your result to variable `usaf_space`'
>>> assert iaf_space is not Ellipsis, \
'Assign your result to variable `iaf_space`'
>>> assert type(armstrong_limit) is int, \
'Variable `armstrong_limit` has invalid type, should be int'
>>> assert type(stratosphere) is int, \
'Variable `stratosphere` has invalid type, should be int'
>>> assert type(usaf_space) is int, \
'Variable `usaf_space` has invalid type, should be int'
>>> assert type(iaf_space) is int, \
'Variable `iaf_space` has invalid type, should be int'
>>> assert armstrong_limit == 19_000, \
'Invalid value for `armstrong_limit`. Check you calculation'
>>> assert stratosphere == 20_000, \
'Invalid value for `stratosphere`. Check you calculation'
>>> assert usaf_space == 80_000, \
'Invalid value for `usaf_space`. Check you calculation'
>>> assert iaf_space == 100_000, \
'Invalid value for `iaf_space`. Check you calculation'
"""
m = 1
km = 1000 * m
# Armstrong limit: 19 kilometers
# type: int
armstrong_limit = ...
# Stratosphere: 20 kilometers
# type: int
stratosphere = ...
# USAF space line: 80 kilometers
# type: int
usaf_space = ...
# IAF space line: 100 kilometers
# type: int
iaf_space = ...
"""
* Assignment: Type Int Mul
* Type: class assignment
* Complexity: easy
* Lines of code: 4 lines
* Time: 3 min
English:
1. Calculate altitude in meters:
a. Armstrong Limit: 19 km
b. Stratosphere: 20 km
c. USAF Space Line: 80 km
d. IAF Space Line: 100 km
2. Use floordiv (`//`) operator
3. Run doctests - all must succeed
Polish:
1. Oblicz wysokości w metrach:
a. Linia Armstronga: 19 km
b. Stratosfera: 20 km
c. Granica kosmosu wg. USAF: 80 km
d. Granica kosmosu wg. IAF 100 km
2. Użyj operatora floordiv (`//`)
3. Uruchom doctesty - wszystkie muszą się powieść
References:
* USAF - United States Air Force
* IAF - International Astronautical Federation
* Kármán line (100 km) - boundary between Earth's atmosphere and space
* Armstrong limit (19 km) - altitude above which atmospheric pressure is
sufficiently low that water boils at the temperature of the human body
Hints:
* Divide (floordiv)
* 1 km = 1000 m
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> assert armstrong_limit is not Ellipsis, \
'Assign your result to variable `armstrong_limit`'
>>> assert stratosphere is not Ellipsis, \
'Assign your result to variable `stratosphere`'
>>> assert usaf_space is not Ellipsis, \
'Assign your result to variable `usaf_space`'
>>> assert iaf_space is not Ellipsis, \
'Assign your result to variable `iaf_space`'
>>> assert type(armstrong_limit) is int, \
'Variable `armstrong_limit` has invalid type, should be int'
>>> assert type(stratosphere) is int, \
'Variable `stratosphere` has invalid type, should be int'
>>> assert type(usaf_space) is int, \
'Variable `usaf_space` has invalid type, should be int'
>>> assert type(iaf_space) is int, \
'Variable `iaf_space` has invalid type, should be int'
>>> assert armstrong_limit == 19_000, \
'Invalid value for `armstrong_limit`. Check you calculation'
>>> assert stratosphere == 20_000, \
'Invalid value for `stratosphere`. Check you calculation'
>>> assert usaf_space == 80_000, \
'Invalid value for `usaf_space`. Check you calculation'
>>> assert iaf_space == 100_000, \
'Invalid value for `iaf_space`. Check you calculation'
"""
m = 1
km = 1000 * m
ARMSTRONG_LIMIT = 19*km
STRATOSPHERE = 20*km
USAF_SPACE = 80*km
IAF_SPACE = 100*km
# Armstrong line: 19 kilometers in meters
# Use floordiv (`//`) operator
# type: int
armstrong_limit = ...
# Stratosphere: 20 kilometers in meters
# Use floordiv (`//`) operator
# type: int
stratosphere = ...
# USAF space line: 80 kilometers in meters
# Use floordiv (`//`) operator
# type: int
usaf_space = ...
# IAF space line: 100 kilometers in meters
# Use floordiv (`//`) operator
# type: int
iaf_space = ...
"""
* Assignment: Type Int Truediv
* Type: class assignment
* Complexity: easy
* Lines of code: 3 lines
* Time: 3 min
English:
1. Define variable in meters:
a. Kármán Line Earth: 100_000 m
b. Kármán Line Mars: 80_000 m
c. Kármán Line Venus: 250_000 m
2. Run doctests - all must succeed
Polish:
1. Zdefiniuj zmienne w metrach:
a. Linia Kármána Ziemia: 100_000 m
b. Linia Kármána Mars: 80_000 m
c. Linia Kármána Wenus: 250_000 m
2. Uruchom doctesty - wszystkie muszą się powieść
References:
* Kármán line (100 km) - boundary between planets's atmosphere and space
Hints:
* Multiply
* 1 km = 1000 m
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> assert karman_line_earth is not Ellipsis, \
'Assign your result to variable `karman_line_earth`'
>>> assert karman_line_mars is not Ellipsis, \
'Assign your result to variable `karman_line_mars`'
>>> assert karman_line_venus is not Ellipsis, \
'Assign your result to variable `karman_line_venus`'
>>> assert type(karman_line_earth) is int, \
'Variable `karman_line_earth` has invalid type, should be int'
>>> assert type(karman_line_mars) is int, \
'Variable `karman_line_mars` has invalid type, should be int'
>>> assert type(karman_line_venus) is int, \
'Variable `karman_line_venus` has invalid type, should be int'
>>> assert karman_line_earth == 100_000, \
'Invalid value for `karman_line_earth`. Check you calculation'
>>> assert karman_line_mars == 80_000, \
'Invalid value for `karman_line_mars`. Check you calculation'
>>> assert karman_line_venus == 250_000, \
'Invalid value for `usaf_space`. Check you calculation'
"""
m = 1
km = 1000 * m
# Kármán Line Earth: 100_000 meters
# type: int
karman_line_earth = ...
# Kármán Line Mars: 80_000 meters
# type: int
karman_line_mars = ...
# Kármán Line Venus: 250_000 meters
# type: int
karman_line_venus = ...
"""
* Assignment: Type Int Truediv
* Type: class assignment
* Complexity: easy
* Lines of code: 3 lines
* Time: 3 min
English:
1. Calculate altitude in kilometers:
a. Kármán Line Earth: 100_000 m
b. Kármán Line Mars: 80_000 m
c. Kármán Line Venus: 250_000 m
2. Use floordiv (`//`) operator
3. Run doctests - all must succeed
Polish:
1. Oblicz wysokości w kilometrach:
a. Linia Kármána Ziemia: 100_000 m
b. Linia Kármána Mars: 80_000 m
c. Linia Kármána Wenus: 250_000 m
2. Użyj operatora floordiv (`//`)
3. Uruchom doctesty - wszystkie muszą się powieść
References:
* Kármán line (100 km) - boundary between planets's atmosphere and space
Hints:
* Divide (floordiv)
* 1 km = 1000 m
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> assert karman_line_earth is not Ellipsis, \
'Assign your result to variable `karman_line_earth`'
>>> assert karman_line_mars is not Ellipsis, \
'Assign your result to variable `karman_line_mars`'
>>> assert karman_line_venus is not Ellipsis, \
'Assign your result to variable `karman_line_venus`'
>>> assert type(karman_line_earth) is int, \
'Variable `karman_line_earth` has invalid type, should be int'
>>> assert type(karman_line_mars) is int, \
'Variable `karman_line_mars` has invalid type, should be int'
>>> assert type(karman_line_venus) is int, \
'Variable `karman_line_venus` has invalid type, should be int'
>>> assert karman_line_earth == 100, \
'Invalid value for `karman_line_earth`. Check you calculation'
>>> assert karman_line_mars == 80, \
'Invalid value for `karman_line_mars`. Check you calculation'
>>> assert karman_line_venus == 250, \
'Invalid value for `usaf_space`. Check you calculation'
"""
m = 1
km = 1000 * m
KARMAN_LINE_EARTH = 100_000*m
KARMAN_LINE_MARS = 80_000*m
KARMAN_LINE_VENUS = 250_000*m
# Kármán Line Earth: 100_000 meters in km
# Use floordiv (`//`) operator
# type: int
karman_line_earth = ...
# Kármán Line Mars: 80_000 meters in km
# Use floordiv (`//`) operator
# type: int
karman_line_mars = ...
# Kármán Line Venus: 250_000 meters in km
# Use floordiv (`//`) operator
# type: int
karman_line_venus = ...
3.1.10. Homework¶
"""
* Assignment: Type Int Bits
* Type: homework
* Complexity: medium
* Lines of code: 3 lines
* Time: 3 min
English:
1. File size is 1337 megabits [Mb]
2. Calculate size in bits [b]
3. Calculate size in kilobits [kb]
4. Use floordiv (`//`) operator
5. Run doctests - all must succeed
Polish:
1. Wielkość pliku to 1337 megabits [Mb]
2. Oblicz wielkość w bitach [b]
3. Oblicz wielkość w kilobitach [kb]
4. Użyj operatora floordiv (`//`)
5. Uruchom doctesty - wszystkie muszą się powieść
Hints:
* Divide (floordiv)
* 1 kb = 1024 b
* 1 Mb = 1024 Kb
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> assert size_bits is not Ellipsis, \
'Assign your result to variable `size_bits`'
>>> assert size_kilobits is not Ellipsis, \
'Assign your result to variable `size_kilobits`'
>>> assert size_megabits is not Ellipsis, \
'Assign your result to variable `size_megabits`'
>>> assert type(size_bits) is int, \
'Variable `size_bits` has invalid type, should be int'
>>> assert type(size_kilobits) is int, \
'Variable `size_kilobits` has invalid type, should be int'
>>> assert type(size_megabits) is int, \
'Variable `size_megabits` has invalid type, should be 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'
"""
b = 1
kb = 1024 * b
Mb = 1024 * kb
SIZE = 1337 * Mb
# SIZE in bits
# Use floordiv (`//`) operator
# type: int
size_bits = ...
# SIZE in kilobits
# Use floordiv (`//`) operator
# type: int
size_kilobits = ...
# SIZE in megabits
# Use floordiv (`//`) operator
# type: int
size_megabits = ...
"""
* Assignment: Type Int Bytes
* Type: homework
* Complexity: easy
* Lines of code: 2 lines
* Time: 3 min
English:
1. File size is 100 megabytes
2. Calculate size in kilobytes
2. Calculate size in megabits
3. Run doctests - all must succeed
Polish:
1. Wielkość pliku to 100 megabajtów
2. Oblicz wielkość w kilobajtach
2. Oblicz wielkość w megabitach
3. Uruchom doctesty - wszystkie muszą się powieść
Hints:
* Divide (floordiv)
* 1 Kb = 1024 b
* 1 Mb = 1024 Kb
* 1 B = 8 b
* 1 KB = 1024 B
* 1 MB = 1024 KB
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> assert size_kilobytes is not Ellipsis, \
'Assign your result to variable `size_kilobytes`'
>>> assert size_megabits is not Ellipsis, \
'Assign your result to variable `size_megabits`'
>>> assert type(size_kilobytes) is int, \
'Variable `size_kilobytes` has invalid type, should be int'
>>> assert type(size_megabits) is int, \
'Variable `size_megabits` has invalid type, should be 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'
"""
b = 1
kb = 1024 * b
Mb = 1024 * kb
B = 8 * b
kB = 1024 * B
MB = 1024 * kB
SIZE = 100 * MB
# SIZE in kilobytes
# Use floordiv (`//`) operator
# type: int
size_kilobytes = ...
# SIZE in megabits
# Use floordiv (`//`) operator
# type: int
size_megabits = ...
"""
* Assignment: Type Int Bandwidth
* Type: homework
* Complexity: easy
* Lines of code: 3 lines
* Time: 3 min
English:
1. Having internet connection with speed 100 Mb/s
2. How long will take to download 100 MB?
3. To calculate time divide file size by speed
4. Note, that all values must be `int` (type cast if needed)
5. Use floordiv (`//`) operator
6. Run doctests - all must succeed
Polish:
1. Mając łącze internetowe 100 Mb/s
2. Ile zajmie ściągnięcie pliku 100 MB?
3. Aby wyliczyć czas podziel wielkość pliku przez prękość
4. Zwróć uwagę, że wszystkie wartości mają być `int`
(rzutuj typ jeżeli potrzeba)
5. Użyj operatora floordiv (`//`)
6. Uruchom doctesty - wszystkie muszą się powieść
Hints:
* Multiply
* Divide (floordiv)
* 1 Kb = 1024 b
* 1 Mb = 1024 Kb
* 1 B = 8 b
* 1 KB = 1024 B
* 1 MB = 1024 KB
Tests:
>>> import sys; sys.tracebacklimit = 0
>>> assert bandwidth is not Ellipsis, \
'Assign your result to variable `bandwidth`'
>>> assert size is not Ellipsis, \
'Assign your result to variable `size`'
>>> assert duration is not Ellipsis, \
'Assign your result to variable `duration`'
>>> assert type(bandwidth) is int, \
'Variable `bandwidth` has invalid type, should be int'
>>> assert type(size) is int, \
'Variable `size` has invalid type, should be int'
>>> assert type(duration) is int, \
'Variable `duration` has invalid type, should be int'
>>> assert bandwidth == 104_857_600, \
'Invalid value for `bandwidth`. Check you calculation'
>>> assert size == 838_860_800, \
'Invalid value for `size`. Check you calculation'
>>> assert duration == 8, \
'Invalid value for `duration`. Check you calculation'
"""
SECOND = 1
b = 1
kb = 1024 * b
Mb = 1024 * kb
B = 8 * b
kB = 1024 * B
MB = 1024 * kB
# 100 megabits per second
# Use floordiv (`//`) operator
# type: int
bandwidth = ...
# 100 megabytes
# type: int
size = ...
# Duration is size by bandwidth in seconds
# Use floordiv (`//`) operator
# type: int
duration = ...