[Tutor] <TUTOR>My first (er...working...) script ever

antonmuhin at rambler.ru antonmuhin at rambler.ru" <antonmuhin@rambler.ru
Mon Feb 24 07:40:15 2003


Hello Predrag,

Saturday, February 22, 2003, 2:17:09 AM, you wrote:

it was debated here and where, but I would rewrite it the following
way:

def processCircle():
    r = float(raw_input("circle radius: ")) # try/except are good here
    print "result is %.3f" % krug(r)

def process...
    # in the same fashion


commands = {
  'k': processCircle,
  ....
  'e': None
}
def main():
   while 1:
      print " 'o'  za opcije"
      print " 'k'  za obim kruga "
      print " 'p'  za obim pravougaonika "
      print " 'c'  za obim kvadrata"
      print " 'e'  za  exit"
      choice = raw_input("opcija : ")
      command = commands[choice]
      if command:
          commmand()
      else:
          break

Defintely, it's just a sketch and might be improved in zillions ways

Anton.
   



PI> import math
PI> import sys

PI> ## simple menu 
PI> def print_options() :
PI>     print " 'o'  za opcije"
PI>     print " 'k'  za obim kruga "
PI>     print " 'p'  za obim pravougaonika "
PI>     print " 'c'  za obim kvadrata"
PI>     print " 'e'  za  exit"
    
PI> ## circle area 
PI> def krug(radius) :
PI>     return  (math.pi*radius)

PI> ##area of rectangle 
PI> def pravougaonik(visina,duzina) :
PI>     return ((visina*2)+(duzina*2))

PI> ## square area
PI> def kvadrat(stranica) :
PI>     return (stranica*4)


PI> choice="o" ##initial value

PI> while choice != "e" :
PI>     if  choice == "k" :
PI>         r=input("poluprecnik kruga :  ")
PI>         print "obim je : ", krug(r)
            
        
PI>     elif choice == "p" :
PI>         v=input ("visina  : ")
PI>         h=input (" duzina :")
PI>         print "obim : ", pravougaonik(v,h)
            
         
PI>     elif choice == "c" :
PI>         d=input ("stranica :") 
PI>         print "obim je : ", kvadrat(d)

PI>     elif choice =="e":
PI>         sys.exit()
            
          
PI>     elif choice != "e":
PI>         print_options()
PI>     choice = raw_input("opcija : ")


PI> ******
PI> </code>

PI>  Thank you.

PI>  Pedja
PI> ---
PI>  "Just below my skin,I'm screaming..."
PI>  Salva Mea,Faithless









-- 
Best regards,
 anton                            mailto:antonmuhin@rambler.ru