Skip to content

development #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions basics/variable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
def main():
"""
>>> a = 3
>>> b = 4
>>> a + b
7
>>> a - b
-1
>>> a * b
12
>>> a / b
0.75
>>> a // b
0
>>> a % b
3
>>> 3 ** 4
81

>>> type(3)
<class 'int'>
>>> type(3.14)
<class 'float'>
>>> type('a')
<class 'str'>
>>> type("abc")
<class 'str'>
>>> type(True)
<class 'bool'>
>>> type(None)
<class 'NoneType'>
>>> type(3 + 4j)
<class 'complex'>

>>> int(3.14)
3
>>> int(-3)
-3
>>> float("3.14")
3.14
>>> str(3.14)
'3.14'
>>> str(3 + 4j)
'(3+4j)'
>>> chr(65)
'A'
>>> chr(97)
'a'
>>> ord("a")
97
>>> ord("A")
65
>>> chr(ord('a') - 32)
'A'
>>> chr(ord('A') + 32)
'a'
"""


if __name__ == "__main__":
from doctest import testmod

testmod()
Empty file added conversions/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions conversions/fahrenheit_to_celsius.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
https://en.wikipedia.org/wiki/Fahrenheit
"""


def fahrenheit_to_celsius(temperature: float) -> float:
"""
>>> fahrenheit_to_celsius(32)
0.0
>>> fahrenheit_to_celsius(39)
3.888888888888889
"""
return 5 * (temperature - 32) / 9


if __name__ == "__main__":
from doctest import testmod

testmod()
3 changes: 2 additions & 1 deletion maths/median.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def median(numbers):
numbers = sorted(numbers)
mid_index = len(numbers) // 2
return (
(numbers[mid_index] + numbers[mid_index - 1]) / 2 if mid_index % 2 == 0
(numbers[mid_index] + numbers[mid_index - 1]) / 2
if mid_index % 2 == 0
else numbers[mid_index]
)

Expand Down
33 changes: 33 additions & 0 deletions maths/mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
https://en.wikipedia.org/wiki/Mode_(statistics)
"""


def mode(numbers):
"""
Calculate mode of a list numbers.
:param numbers: the numbers
:return: mode number of the numbers.

>>> mode([1, 2, 2, 3, 4, 7, 9])
2
"""
max_count = 1
mode_number = numbers[0]

for number in numbers:
count = 0
for temp in numbers:
if temp == number:
count += 1
if count > max_count:
max_count = count
mode_number = number

return mode_number


if __name__ == "__main__":
from doctest import testmod

testmod()