-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabv.py
81 lines (73 loc) · 2.4 KB
/
abv.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
abv_multiplier = 131
#abv_multiplier = 129
try:
from Gui import *
gui_present = True
except:
gui_present = False
def calculate_abv(og,fg):
return str('%.2f' % (abv_multiplier * (float(og) - float(fg)))) + '%'
def calculate_attenuation(og,fg):
return str('%.2f' % (100 * (1 - (float(fg) - 1)/(float(og) - 1)))) + '%'
def results_controller():
try:
abv.delete(0, END)
abv.insert(0, calculate_abv(original_gravity.get(),final_gravity.get()))
attenuation.delete(0, END)
attenuation.insert(0, calculate_attenuation(original_gravity.get(),final_gravity.get()))
except:
display_error()
def display_error():
error_window = Gui()
error_window.title('Error')
error_window.la('')
error_window.gr(cols=3)
error_window.la(' ')
error_window.la('Error with your inputs')
error_window.la(' ')
error_window.endgr()
error_window.la('')
if gui_present:
main_window = Gui()
main_window.title('Attenuation and ABV Calculator')
main_window.la('')
main_window.gr(cols=3)
main_window.la('Original Gravity:')
original_gravity = main_window.en(text='')
main_window.la(' ')
main_window.la('Ending Gravity:')
final_gravity = main_window.en(text='')
main_window.la(' ')
main_window.endgr()
main_window.la('')
main_window.gr(cols=3)
main_window.la(' ')
main_window.bu(text='Calculate Attenuation and ABV', command=results_controller)
main_window.la(' ')
main_window.endgr()
main_window.la('')
main_window.gr(cols=3)
main_window.la('Attenuation:')
attenuation = main_window.en(text='')
main_window.la(' ')
main_window.la('Alcohol By Volume:')
abv = main_window.en(text='')
main_window.la(' ')
main_window.endgr()
main_window.la('')
main_window.mainloop()
else:
print 'type \'q\' or \'quit\' to quit'
while True:
original_gravity = raw_input('Original Gravity: ')
if original_gravity[0].lower() == 'q':
break
final_gravity = raw_input('Ending Gravity: ')
if final_gravity[0].lower() == 'q':
break
print ''
try:
print 'Attenuation: ' + calculate_attenuation(original_gravity,final_gravity)
print 'Alcohol by Volume: ' + calculate_abv(original_gravity,final_gravity) + '\n'
except:
print 'Error with your inputs\n'