-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_function.py
More file actions
87 lines (80 loc) · 1.45 KB
/
test_function.py
File metadata and controls
87 lines (80 loc) · 1.45 KB
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
# %%
x = 2
print(x*2)
# %%
def testfunc(x):
return(2*x)
# %%
y = testfunc(3)
print(y)
# %%
testfunc(3)
# %%
def fahr_to_celsius(temp_f):
return((temp_f - 32) * (5/9))
# %%
fahr_to_celsius(98)
# %%
freeze = fahr_to_celsius(32)
# %%
print(freeze)
# %%
print('Boiling point:', fahr_to_celsius(212), "C")
# %%
def celsius_to_kelvin(temp_c):
return(temp_c + 273.15)
# %%
celsius_to_kelvin(100)
# %%
def fahr_to_kelvin(temp_f):
"""Returns the conversion from Fahrenheit to Kelvin
Usage:
fahr_to_kelvin(212) = 373.15
"""
temp_c = fahr_to_celsius(temp_f)
temp_k = celsius_to_kelvin(temp_c)
return(temp_k)
# %%
fahr_to_kelvin(212)
# %%
fahr_to_kelvin(32)
# %%
help(fahr_to_kelvin)
# %%
help(print)
# %%
def test_add(a, b):
return(a + b)
# %%
test_add(2,7)
# %%
def test_display(a, b, c = 3):
print("a", a, "b", b, "c", c)
return
# %%
test_display(1,2)
# %%
test_display(1,2,c=7)
# %%
fahr_to_kelvin("forty-two")
# %%
def s(p):
a = 0
for v in p:
a += v
m = a / len(p)
d = 0
for v in p:
d += (v - m) * (v - m)
return numpy.sqrt(d / (len(p) - 1))
# %%
def std_dev(sample):
sample_sum = 0
for value in sample:
sample_sum += value
sample_mean = sample_sum / len(sample)
sum_squared_devs = 0
for value in sample:
sum_squared_devs += (value - sample_mean) * (value - sample_mean)
return numpy.sqrt(sum_squared_devs / (len(sample) - 1))
# %%