-
Notifications
You must be signed in to change notification settings - Fork 9
/
my_python_functions.py
115 lines (88 loc) · 2.4 KB
/
my_python_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import numpy as np
import scipy
def calc_mean(x: np.ndarray) -> float:
"""Calculate the mean of an array of numbers.
Parameters
----------
x : array-like
The array of numbers for which the mean is calculated.
Returns
-------
mean : float
The mean of the input array of numbers.
"""
return np.mean(x)
def calc_median(x: np.ndarray) -> float:
"""Calculate the median of an array of numbers.
Parameters
----------
x : array-like
The array of numbers for which the median is calculated.
Returns
-------
median : float
The median of the input array of numbers.
"""
return np.median(x)
def calc_std(x: np.ndarray) -> float:
"""Calculate the standard deviation of an array of numbers
Parameters
----------
x : np.ndarray
The array of numbers
Returns
-------
float
The standard deviation of the input array
"""
return np.std(x)
def calc_add(x: float, y: float) -> float:
"""Calculate the sum of two numbers.
Parameters
----------
x : float
The first number.
y : float
The second number.
Returns
-------
sum : float
The sum of the two input numbers.
"""
return x + y
def calc_sub(x: float, y: float) -> float:
"""Calculate the difference between 2 numbers
Parameters
----------
x : float
The first number
y : float
The second number
Returns
-------
float
The difference
"""
return x - y
def print_my_name(name: str) -> None:
if not isinstance(name, str):
raise ValueError("The input must be a string.")
print("Hello, my name is", name)
def print_something_nice() -> None:
print("You are doing a REALLY great job!")
def am_i_cool(name):
cool_people = ['Alice', 'Bob', 'Charlie']
if name in cool_people:
return f"{name}, you are definitely cool! 😎"
else:
return f"{name}, you're cool in your own special way! 🦄"
def print_age(birth_year: float) -> None:
print(f"I am {2024 - birth_year} years old.")
def print_happy_halloween():
print("Happy Halloween!!:)")
def print_favorite_animal(animal):
if not isinstance(animal, str):
raise ValueError("Input must be a string.")
print("My favorite animal is", animal)
def print(try_number):
print("This is try number:",str(try_number))