Created
December 7, 2018 17:15
-
-
Save ashkantaravati/6d532a3316f543005193a0f2399a523b to your computer and use it in GitHub Desktop.
python scripts I used for easing my calculations while writing lab report about Newton's 2nd law.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pprint | |
def calc_tuple(x, t): | |
x_twice = round(2 * x,1) | |
t_times2 = round(t**2,2) | |
a = round(x_twice/t_times2, 2) | |
return (x,x_twice,t,t_times2,a) | |
def calc_table(tuple_list): | |
count = len(tuple_list) | |
sum = 0 | |
for item in tuple_list: | |
sum+=item[4] | |
avg_a = round(sum/count,2) | |
def abs_delta(el): | |
ai = el[4] | |
delta = abs(avg_a - ai) | |
res = round(delta,2) | |
return res | |
table = [(item,abs_delta(item)) for item in tuple_list] | |
table.append(('average:',avg_a)) | |
return table | |
cases = [ | |
(0.4,0.86), | |
(0.5,0.99), | |
(0.6,1.07), | |
(0.7,1.21) | |
] | |
table = [calc_tuple(x,t) for (x,t) in cases] | |
calculated = calc_table(table) | |
pp = pprint.PrettyPrinter(indent=4) | |
pp.pprint(calculated) | |
#[ ((0.4, 0.8, 0.86, 0.74, 1.08), 0.05), | |
# ((0.5, 1.0, 0.99, 0.98, 1.02), 0.01), | |
# ((0.6, 1.2, 1.07, 1.14, 1.05), 0.02), | |
# ((0.7, 1.4, 1.21, 1.46, 0.96), 0.07), | |
# ('average:', 1.03)] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment