R=.082057
def intro(n):
 print("+----------------------+");print("| "+n+" |");print("|   ___(o )> quack!    |");print("|   by DuckieDai       |");print("+----------------------+");input("ENTER to start: ")
def num(s):
 while 1:
  try:return float(input(s))
  except:print("Enter a number")
def pos(s):
 while 1:
  x=num(s)
  if x>0:return x
  print("Must be positive")
def nonneg(s):
 while 1:
  x=num(s)
  if x>=0:return x
  print("Must be 0 or more")
def pick(s,m):
 while 1:
  try:
   x=int(input(s))
   if x>0 and x<=m:return x
  except:pass
  print("Invalid choice")
intro("VAN DER WAALS")
print("1 Pressure 2 Temp");print("3 Real vs ideal 4 Find a/b")
c=pick("Choose 1-4: ",4)
if c==1 or c==3:
 n=pos("Moles n: ");v=pos("Volume L: ");t=pos("Temp K: ");a=nonneg("a: ");b=nonneg("b: ")
 if v<=n*b:print("Need V > n*b")
 elif c==1:print("P atm =",n*R*t/(v-n*b)-a*n**2/v**2)
 else:
  pi=n*R*t/v;pr=n*R*t/(v-n*b)-a*n**2/v**2;print("Ideal P =",pi);print("Real P =",pr);print("% change =",100*(pr-pi)/pi)
elif c==2:
 p=pos("P atm: ");n=pos("Moles n: ");v=pos("Volume L: ");a=nonneg("a: ");b=nonneg("b: ")
 if v<=n*b:print("Need V > n*b")
 else:print("T K =",(p+a*n**2/v**2)*(v-n*b)/(n*R))
else:
 q=pick("1 find a 2 find b: ",2);p=pos("P atm: ");n=pos("Moles n: ");v=pos("Volume L: ");t=pos("Temp K: ")
 if q==1:
  b=nonneg("b: ")
  if v<=n*b:print("Need V > n*b")
  else:print("a =",v**2/n**2*(n*R*t/(v-n*b)-p))
 else:
  a=nonneg("a: ");print("b =",(v-n*R*t/(p+a*n**2/v**2))/n)
input("ENTER for guide: ");print("a=attractions, b=molecule volume");print("V must exceed n*b");print("DuckieDai: done!");input("ENTER to exit: ")
