mirror of
https://github.com/Justuser3310/ss14_chemistry_site.git
synced 2025-01-19 01:08:48 +00:00
Добавлены ещё округления
This commit is contained in:
parent
27650b875f
commit
51023cd897
23
calc.py
23
calc.py
@ -12,16 +12,11 @@ def sround(num):
|
||||
num = floor(num)
|
||||
|
||||
# Подмены
|
||||
rep = [[16,15], [33,30]]
|
||||
rep = [[16,15], [33,30], [21,20], [12,10], [8,5]]
|
||||
|
||||
for i in rep:
|
||||
if num == i[0]:
|
||||
num = i[1]
|
||||
# Делаем около-кратным 10 и 15
|
||||
# if abs(num - round(num/10)*10) <= 1:
|
||||
# num = round(num/10)*10
|
||||
# if abs(num - round(num/15)*15) <= 1:
|
||||
# num = round(num/15)*15
|
||||
|
||||
return num
|
||||
|
||||
@ -31,11 +26,18 @@ def calc(el, amount, main = False):
|
||||
recipe = {}
|
||||
|
||||
comps = db[el][1:] # Получаем составные
|
||||
out = db[el][0] #Количество на выходе
|
||||
|
||||
# Считаем количество частей
|
||||
parts = 0
|
||||
for i in comps:
|
||||
parts += i[1]
|
||||
|
||||
# Делаем поправку на выход
|
||||
if out < parts:
|
||||
print(el, ': ',out,' < ', parts)
|
||||
parts = out
|
||||
|
||||
# Считаем 1 часть
|
||||
part = sround(amount/parts)
|
||||
|
||||
@ -63,15 +65,10 @@ def calc(el, amount, main = False):
|
||||
recipe[i[0]] += part*i[1]
|
||||
|
||||
if main:
|
||||
print('PART: ', part)
|
||||
return [recipe, parts*part]
|
||||
else:
|
||||
print('PART: ', part)
|
||||
return part*parts
|
||||
|
||||
#calc("Бикаридин", 100)
|
||||
#calc("Эпинефрин", 100)
|
||||
#print( calc("Лексорин", 100, True))
|
||||
#calc("Амбузол", 100)
|
||||
#calc("Амбузол плюс", 100)
|
||||
#print( calc("Аммиак", 100, True) )
|
||||
|
||||
#print(recipe)
|
||||
|
Loading…
Reference in New Issue
Block a user