Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local percents = {26.7,12.1,61.2}
- local grams = {}
- local weight = {30.973761,14.00674,35.4527}
- local name = {"P","N","Cl"}
- local vals = {1,1,2}
- local times_by = 1
- function round(number,deci)
- local num = tostring(number)
- local num2 = ""
- local num3 = ""
- local num4
- local savevar1 = ""
- for i=1,#num do
- if string.sub(num,i,i+1):lower() == "e+" then
- savevar1 = string.sub(num,i+2)
- num2 = string.sub(num,1,i-1)
- break
- end
- end
- if num2 ~= "" then num = num2 end
- for i=1,#num do
- if string.sub(num,i,i) == "." then
- num3 = tonumber(string.sub(num,deci+i+1,deci+i+1))
- num4 = tonumber(string.sub(num,deci+i,deci+i))
- if num3 == "" or num3 == nil then break end
- if num3 >= 5 then
- num = string.sub(num,1,i-1+deci)..tostring(num4+1)
- else
- num = string.sub(num,1,i-1+deci)..tostring(num4)
- end
- end
- end
- if savevar1 ~= "" then
- num = num.." * 10"..supernumbers(savevar1)
- end
- return num
- end
- function roundwhole(x)
- local y = tostring(x)
- for i=1,#y do
- if string.sub(y,i,i) == "." then
- local num1 = tonumber(string.sub(y,i-1,i-1))
- local num2 = tonumber(string.sub(y,i+1,i+1))
- if num2 >= 5 then
- num1 = num1 + 1
- end
- return tonumber(string.sub(y,1,i-2)..num1)
- end
- end
- end
- for i=1,#percents do
- local tek = percents[i] * (1/weight[i])
- table.insert(grams,tek)
- end
- local j = grams[1]
- local sav = {}
- for i=1,#grams do
- print(name[i].." | "..grams[i])
- if grams[i] < j then
- j = grams[i]
- end
- end
- print("--------------------------------")
- print("Moles: "..j)
- print("--------------------------------")
- local g = 0
- for i=1,#weight do
- g = g + (weight[i]*vals[i])
- end
- print("Empirical Molar Mass: "..round(g,1))
- print("--------------------------------")
- for i=1,#grams do
- table.insert(sav,round((grams[i]/j)--[[*times_by]],1))
- end
- for i=1,#sav do
- print(name[i].." | "..sav[i]*times_by)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement