mathphys68ee.py

Created by laigna

Created on March 14, 2026

6.23 KB

Geomeetria, kiirus/teepikkus/aeg, tihedus, protsendid, Pythagorase teoreem, keskmine/statistika


# MathPhys 6-8 EE - NumWorks
# Created by Pärle Laigna - https://parle.laigna.com
# Nooled:vali OK:kinnita Back:tagasi
from kandinsky import fill_rect as F,draw_string as D
from ion import keydown as K
from time import sleep as Z
from math import pi,sqrt
SW,SH=320,222
BK=(0,)*3;WH=(255,)*3
BL=(50,110,230);TL=(0,190,190)
YL=(220,200,60);GN=(60,190,60)
DG=(120,)*3;HD=(30,)*3

okv=1 if K(4)or K(52) else 0

def okd():
 return K(4)or K(52)

def okp():
 global okv
 d=okd()
 if d and not okv:
  okv=1
  return True
 if not d:okv=0
 return False

def wup():
 while okd():Z(0.02)
 Z(0.12)

def menu(title,items,sub=False):
 sel=0;n=len(items)
 while True:
  F(0,0,SW,SH,BK)
  D(title,SW//2-len(title)*5,6,TL,BK)
  F(0,24,SW,2,(40,)*3)
  for i in range(n):
   y=34+i*22
   if i==sel:
    F(8,y,SW-16,20,BL)
    D("> "+items[i],14,y+2,WH,BL)
   else:
    D("  "+items[i],14,y+2,DG,BK)
  if sub:D("Back=tagasi",100,SH-16,(60,)*3,BK)
  else:D("Back=valju",115,SH-16,(60,)*3,BK)
  while True:
   if K(1):sel=(sel-1)%n;Z(0.15);break
   if K(2):sel=(sel+1)%n;Z(0.15);break
   if okp():wup();return sel
   if K(17):return-1
   Z(0.04)

def inp(prompt):
 try:
  v=input(prompt)
  return float(v)
 except:return None

def show(lines):
 F(0,0,SW,SH,BK)
 D("TULEMUS",125,6,TL,BK)
 F(0,24,SW,2,(40,)*3)
 for i,ln in enumerate(lines):
  c=YL if i==len(lines)-1 else WH
  D(str(ln),14,34+i*20,c,BK)
 D("OK=tagasi",120,SH-16,DG,BK)
 while True:
   if okp()or K(17):wup();return
   Z(0.04)

def f_rect():
 l=inp("Pikkus: ")
 w=inp("Laius: ")
 if l and w:
  show(["Ristkulik","l="+str(l)+" w="+str(w),
   "Pindala = l x w","S = "+str(round(l*w,4)),
   "Umbermoodu = 2(l+w)","P = "+str(round(2*(l+w),4))])

def f_tri():
 b=inp("Alus: ")
 h=inp("Korgus: ")
 if b and h:
  show(["Kolmnurk","a="+str(b)+" h="+str(h),
   "Pindala = a x h / 2",
   "S = "+str(round(b*h/2,4))])

def f_circle():
 r=inp("Raadius: ")
 if r:
  show(["Ring","r="+str(r),
   "Pindala = pi x r^2",
   "S = "+str(round(pi*r*r,4)),
   "Umbermoodu = 2 x pi x r",
   "C = "+str(round(2*pi*r,4))])

def f_trap():
 a=inp("Kulg a (ules): ")
 b=inp("Kulg b (all): ")
 h=inp("Korgus: ")
 if a and b and h:
  show(["Trapets",
   "a="+str(a)+" b="+str(b)+" h="+str(h),
   "Pindala = (a+b)/2 x h",
   "S = "+str(round((a+b)/2*h,4))])

def f_box():
 l=inp("Pikkus: ")
 w=inp("Laius: ")
 h=inp("Korgus: ")
 if l and w and h:
  show(["Risttahukas",
   "l="+str(l)+" w="+str(w)+" h="+str(h),
   "Ruumala = l x w x h",
   "V = "+str(round(l*w*h,4)),
   "Pindala = 2(lw+lh+wh)",
   "S = "+str(round(2*(l*w+l*h+w*h),4))])

def f_cyl():
 r=inp("Raadius: ")
 h=inp("Korgus: ")
 if r and h:
  show(["Silinder","r="+str(r)+" h="+str(h),
   "Ruumala = pi x r^2 x h",
   "V = "+str(round(pi*r*r*h,4)),
   "Pindala = 2*pi*r*(r+h)",
   "S = "+str(round(2*pi*r*(r+h),4))])

def f_speed():
 c=menu("Kiirus/Teepikkus/Aeg",
  ["v = s / t  (leia kiirus)",
   "s = v x t  (leia teepikkus)",
   "t = s / v  (leia aeg)"],True)
 if c==0:
  d=inp("Teepikkus: ");t=inp("Aeg: ")
  if d and t and t!=0:
   show(["Kiirus = teepikkus / aeg",
    "s="+str(d)+" t="+str(t),
    "v = "+str(round(d/t,4))])
 elif c==1:
  v=inp("Kiirus: ");t=inp("Aeg: ")
  if v and t:
   show(["Teepikkus = kiirus x aeg",
    "v="+str(v)+" t="+str(t),
    "s = "+str(round(v*t,4))])
 elif c==2:
  d=inp("Teepikkus: ");v=inp("Kiirus: ")
  if d and v and v!=0:
   show(["Aeg = teepikkus / kiirus",
    "s="+str(d)+" v="+str(v),
    "t = "+str(round(d/v,4))])

def f_dens():
 c=menu("Tihedus",
  ["p = m / V  (leia tihedus)",
   "m = p x V  (leia mass)",
   "V = m / p  (leia ruumala)"],True)
 if c==0:
  m=inp("Mass: ");v=inp("Ruumala: ")
  if m and v and v!=0:
   show(["Tihedus = mass / ruumala",
    "m="+str(m)+" V="+str(v),
    "p = "+str(round(m/v,4))])
 elif c==1:
  p=inp("Tihedus: ");v=inp("Ruumala: ")
  if p and v:
   show(["Mass = tihedus x ruumala",
    "p="+str(p)+" V="+str(v),
    "m = "+str(round(p*v,4))])
 elif c==2:
  m=inp("Mass: ");p=inp("Tihedus: ")
  if m and p and p!=0:
   show(["Ruumala = mass / tihedus",
    "m="+str(m)+" p="+str(p),
    "V = "+str(round(m/p,4))])

def f_pct():
 c=menu("Protsendid",
  ["% arvust  (x% y-st)",
   "Mitu %?  (x on ?% y-st)",
   "Leia tervik (x on p% ?-st)"],True)
 if c==0:
  p=inp("Protsent: ");n=inp("Arv: ")
  if p is not None and n is not None:
   show([str(p)+"% arvust "+str(n),
    "= "+str(round(p/100*n,4))])
 elif c==1:
  x=inp("Osa: ");y=inp("Tervik: ")
  if x is not None and y and y!=0:
   show([str(x)+" on mitu % arvust "+str(y)+"?",
    "= "+str(round(x/y*100,4))+"%"])
 elif c==2:
  x=inp("Osa: ");p=inp("Protsent: ")
  if x is not None and p and p!=0:
   show([str(x)+" on "+str(p)+"% millest?",
    "= "+str(round(x/(p/100),4))])

def f_pyth():
 c=menu("Pythagorase teoreem",
  ["Leia c (hupotenuus)",
   "Leia a voi b (kaatet)"],True)
 if c==0:
  a=inp("Kaatet a: ");b=inp("Kaatet b: ")
  if a and b:
   c2=sqrt(a*a+b*b)
   show(["a^2 + b^2 = c^2",
    "a="+str(a)+" b="+str(b),
    "c = sqrt("+str(round(a*a,2))+"+"+str(round(b*b,2))+")",
    "c = "+str(round(c2,6))])
 elif c==1:
  c2=inp("Hupotenuus c: ");a=inp("Kaatet a: ")
  if c2 and a and c2>a:
   b=sqrt(c2*c2-a*a)
   show(["b = sqrt(c^2 - a^2)",
    "c="+str(c2)+" a="+str(a),
    "b = "+str(round(b,6))])

def f_avg():
 print("\n"*20+"Sisesta arvud, tyhi=valmis")
 nums=[]
 while True:
  v=input("Vaartus "+str(len(nums)+1)+": ").strip()
  if not v:break
  try:nums.append(float(v))
  except:pass
 if nums:
  s=sum(nums);n=len(nums)
  nums.sort()
  med=nums[n//2]if n%2 else(nums[n//2-1]+nums[n//2])/2
  show(["Keskmine / Statistika",
   "Kogus: "+str(n),
   "Summa: "+str(round(s,4)),
   "Keskmine: "+str(round(s/n,4)),
   "Mediaan: "+str(round(med,4)),
   "Min: "+str(nums[0])+" Max: "+str(nums[-1])])

CATS=[
 "Geomeetria - Pindala",
 "Geomeetria - Ruumala",
 "Kiirus / Teepikkus / Aeg",
 "Tihedus",
 "Protsendid",
 "Pythagorase teoreem",
 "Keskmine / Statistika"]
def run():
 while True:
  c=menu("MathPhys 6-8 EE",CATS)
  if c<0:return
  if c==0:
   while True:
    s=menu("Pindala",["Ristkulik","Kolmnurk",
     "Ring","Trapets"],True)
    if s<0:break
    [f_rect,f_tri,f_circle,f_trap][s]()
  elif c==1:
   while True:
    s=menu("Ruumala",["Risttahukas",
     "Silinder"],True)
    if s<0:break
    [f_box,f_cyl][s]()
  elif c==2:f_speed()
  elif c==3:f_dens()
  elif c==4:f_pct()
  elif c==5:f_pyth()
  elif c==6:f_avg()
run()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.