[Tutor] <TUTOR>My first (er...working...) script ever
Predrag Ivanovic
Predrag Ivanovic <predivan@ptt.yu>
Sat Feb 22 16:04:03 2003
Hello...
Programming and Python are pretty much new to me,but it's been fun so far...
So,i would like comments on code below,especially on style(or lack of it..)
It's pretty much trivial,one of the exercises from Josh Cogliati's "Non-Programmers
Tutorial For Python",available thru link from PythonLabs(www.python.org),i
recomend it for newcomers.
It has basic functionality(it works...),but it lacks error handling and possibly
a few other things.
Maybe ,when i learn more about Tkinter,i'll add a GUI and send it to
UselessPython :)
Anyway,here comes nothing :
<code>
*****
## exercise from chapter 5 (functions)##
## choose from a menu to calculate ##
## area of circle,rectangle or square ##
import math
import sys
## simple menu
def print_options() :
print " 'o' za opcije"
print " 'k' za obim kruga "
print " 'p' za obim pravougaonika "
print " 'c' za obim kvadrata"
print " 'e' za exit"
## circle area
def krug(radius) :
return (math.pi*radius)
##area of rectangle
def pravougaonik(visina,duzina) :
return ((visina*2)+(duzina*2))
## square area
def kvadrat(stranica) :
return (stranica*4)
choice="o" ##initial value
while choice != "e" :
if choice == "k" :
r=input("poluprecnik kruga : ")
print "obim je : ", krug(r)
elif choice == "p" :
v=input ("visina : ")
h=input (" duzina :")
print "obim : ", pravougaonik(v,h)
elif choice == "c" :
d=input ("stranica :")
print "obim je : ", kvadrat(d)
elif choice =="e":
sys.exit()
elif choice != "e":
print_options()
choice = raw_input("opcija : ")
******
</code>
Thank you.
Pedja
---
"Just below my skin,I'm screaming..."
Salva Mea,Faithless