Skip to content

Commit 8ef2c65

Browse files
Merge pull request #9 from examplehub/dev
development
2 parents 1bac335 + 99a73ac commit 8ef2c65

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

basics/variable.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
def main():
2+
"""
3+
>>> a = 3
4+
>>> b = 4
5+
>>> a + b
6+
7
7+
>>> a - b
8+
-1
9+
>>> a * b
10+
12
11+
>>> a / b
12+
0.75
13+
>>> a // b
14+
0
15+
>>> a % b
16+
3
17+
>>> 3 ** 4
18+
81
19+
20+
>>> type(3)
21+
<class 'int'>
22+
>>> type(3.14)
23+
<class 'float'>
24+
>>> type('a')
25+
<class 'str'>
26+
>>> type("abc")
27+
<class 'str'>
28+
>>> type(True)
29+
<class 'bool'>
30+
>>> type(None)
31+
<class 'NoneType'>
32+
>>> type(3 + 4j)
33+
<class 'complex'>
34+
35+
>>> int(3.14)
36+
3
37+
>>> int(-3)
38+
-3
39+
>>> float("3.14")
40+
3.14
41+
>>> str(3.14)
42+
'3.14'
43+
>>> str(3 + 4j)
44+
'(3+4j)'
45+
>>> chr(65)
46+
'A'
47+
>>> chr(97)
48+
'a'
49+
>>> ord("a")
50+
97
51+
>>> ord("A")
52+
65
53+
>>> chr(ord('a') - 32)
54+
'A'
55+
>>> chr(ord('A') + 32)
56+
'a'
57+
"""
58+
59+
60+
if __name__ == "__main__":
61+
from doctest import testmod
62+
63+
testmod()

conversions/__init__.py

Whitespace-only changes.

conversions/fahrenheit_to_celsius.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
https://en.wikipedia.org/wiki/Fahrenheit
3+
"""
4+
5+
6+
def fahrenheit_to_celsius(temperature: float) -> float:
7+
"""
8+
>>> fahrenheit_to_celsius(32)
9+
0.0
10+
>>> fahrenheit_to_celsius(39)
11+
3.888888888888889
12+
"""
13+
return 5 * (temperature - 32) / 9
14+
15+
16+
if __name__ == "__main__":
17+
from doctest import testmod
18+
19+
testmod()

maths/mode.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
https://en.wikipedia.org/wiki/Mode_(statistics)
3+
"""
4+
5+
6+
def mode(numbers):
7+
"""
8+
Calculate mode of a list numbers.
9+
:param numbers: the numbers
10+
:return: mode number of the numbers.
11+
12+
>>> mode([1, 2, 2, 3, 4, 7, 9])
13+
2
14+
"""
15+
max_count = 1
16+
mode_number = numbers[0]
17+
18+
for number in numbers:
19+
count = 0
20+
for temp in numbers:
21+
if temp == number:
22+
count += 1
23+
if count > max_count:
24+
max_count = count
25+
mode_number = number
26+
27+
return mode_number
28+
29+
30+
if __name__ == "__main__":
31+
from doctest import testmod
32+
33+
testmod()

0 commit comments

Comments
 (0)