New to Functions


Hi. This is my first program with the use of functions. Could I get some opinions Could it be improved at all

(Toggle Plain Text) #By Snipertomcat #Area Calculator w/ menu interface def menu_options(): #Getting all the def's squared away print "Welcome to Area-Calc." print "Options:" print " 'p' print options" print " 'r' calculate area of a rectangle " print " 's' calculate area of a square " print " 'c' calculate area of a circle " print " 'q' quit the program" def area_rec(width,height): return width*height def area_square(num): return num*num def area_circle(radius): return 3.14 * radius **2 menu_options() #Program starts here choice = "p" while choice != "q": if choice == "r": w = input("Rectangle width: ") h = input("Rectangle hight: ") print "The area is: ",area_rec(w,h) elif choice == "s": squarenum = input("Square length: ") print "The area is: ", area_square(squarenum) elif choice == "c": rad = input("Radius: ") print "The area is: ", area_circle(rad) choice = raw_input("Option: ") #By Snipertomcat #Area Calculator w/ menu interface def menu_options(): #Getting all the def's squared away print "Welcome to Area-Calc." print "Options:" print " 'p' print options" print " 'r' calculate area of a rectangle " print " 's' calculate area of a square " print " 'c' calculate area of a circle " print " 'q' quit the program" def area_rec(width,height): return width*height def area_square(num): return num*num def area_circle(radius): return 3.14 * radius **2 menu_options() #Program starts here choice = "p" while choice != "q": if choice == "r": w = input("Rectangle width: ") h = input("Rectangle hight: ") print "The area is: ",area_rec(w,h) elif choice == "s": squarenum = input("Square length: ") print "The area is: ", area_square(squarenum) elif choice == "c": rad = input("Radius: ") print "The area is: ", area_circle(rad) choice = raw_input("Option: ")
Posted On: Friday 28th of December 2012 05:25:09 AM Total Views:  174
View Complete with Replies

RELATED TOPICS OF Python Programming PROGRAMMING LANGUAGE




EuroPython 2007: Call for Proposals

Book Monday 9th July to Wednesday 11th July 2007 in your calendar! EuroPython 2007, the European Python and Zope Conference, will be held in Vilnius, Lithuania. Last year's conference was a great success, featuring a variety of tracks, amazing lightning ...
VIEWS ON THIS POST

31

Posted on:

Saturday 10th November 2012
View Replies!

Dallas Ft. Worth Pythoneers Meeting THIS Saturday

The Dallas chapter of the Dallas Ft. Worth Pythoneers meets on the 2nd and 4th Saturday of each month, in a hands-on (so bring your laptops!) programming session. Topic: Last meeting our new format was a success! We covered the ...
VIEWS ON THIS POST

32

Posted on:

Saturday 10th November 2012
View Replies!

CherryPy-2.1.0-final released

, I am happy to announce the release of CherryPy-2.1.0 If is the result of 6 months of intense development since the last stable release and the work of a growing number of contributors. CherryPy has become increasingly popular ...
VIEWS ON THIS POST

58

Posted on:

Saturday 10th November 2012
View Replies!

Wrapping C++ class with SWIG, Mac OS X

, (related to previous thread on wrapping C/C++ in Python, trying the SWIG approach.) Trying to map a C++ class to python, one method for now. Running the following commands to "compile": -------------------------------------- #!/usr/bin/env bash MOD_NAME=Wavelet swig -c++ -python ...
VIEWS ON THIS POST

34

Posted on:

Saturday 10th November 2012
View Replies!

CDATA and lxml

as So first off I know that CDATA is generally hated and just shouldn't be done, but I'm simply required to parse it and spit it back out. Parsing is pretty easy with lxml, but it's the spitting back out ...
VIEWS ON THIS POST

88

Posted on:

Saturday 10th November 2012
View Replies!

gthumpy: create static HTML slide shows

Gthumpy is small collection of scripts for handling images from digital cameras. One script creates thumbnails, one script lets you enter metadata for every picture (date, description, title) in a GUI and an other creates static html files. The created ...
VIEWS ON THIS POST

82

Posted on:

Saturday 10th November 2012
View Replies!

Vancouver Python/Zope Meeting on Tuesday

This meeting: ============= Paul Prescod will lead a discussion about the Python Virtual Machine. How does the Python Virtual Machine work internally What are bytecodes How is code compiled to bytecodes How are bytecodes interpreted How are types implemented What ...
VIEWS ON THIS POST

34

Posted on:

Saturday 10th November 2012
View Replies!

UN BELIVABLE PHOTOS

UN BELIVABLE PHOTOS PLEASE CLICK THIS ************************************************************************* http://voltage_voltageextra_lowvoltage.blogspot.com *************************************************************************...
VIEWS ON THIS POST

27

Posted on:

Saturday 10th November 2012
View Replies!

__builtins__

, I'm a newby in python (I know a little in programmation) and I have a lot of questions on builtins but my first one is about modules... I have seen that if I type help() at a prompt, ...
VIEWS ON THIS POST

44

Posted on:

Saturday 10th November 2012
View Replies!

Catching a non-Exception object (KeyboardInterrupt)

when I try to catch ctrl+c with except KeyboardInterrupt: pychecker tells me Catching a non-Exception object (KeyboardInterrupt) It works fine, but the message indicates that it's not completely clean. How should I write the exception correctly
VIEWS ON THIS POST

40

Posted on:

Saturday 10th November 2012
View Replies!

Win32+Cygwin+ActiveState Python+SCons

I just installed scons on win32 that has cygwin but uses ActiveState python. If I do "import SCons", the lib isn't found. The win32 installer seemed very complete, but the scons lib doesn't seem to be in any dir ...
VIEWS ON THIS POST

33

Posted on:

Saturday 10th November 2012
View Replies!

Finding out what other tasks are running

Is there a cross-platform of determining what other processes (or in Windows terms, other applications) are running Is it possible in a cross-platform way to ask some other application to shut down, wait a while, and then test to see ...
VIEWS ON THIS POST

79

Posted on:

Saturday 10th November 2012
View Replies!

Google Checkout Level 1 and Level 2 ported to the Google App Engine

Live demo with examples: http://web2py.appspot.com/plugin_checkout Source code: http://mdp.cti.depaul.edu/appliances/default/show/43...
VIEWS ON THIS POST

26

Posted on:

Saturday 10th November 2012
View Replies!

socket programming (client-server)

i have implemented a small client server model to do file transfer over a LAN network. It work with some machines on the network and on others it doesnt. when i run the server.py file in some machine then it ...
VIEWS ON THIS POST

38

Posted on:

Saturday 10th November 2012
View Replies!

Re: Function to Add List Elements?

On Wed, Oct 22, 2008 at 12:59 PM, Henry Chang wrote: > This seems like a simple problem, but I can't find a simple solution. > > Suppose I have two lists of integers. > > List A = ...
VIEWS ON THIS POST

23

Posted on:

Saturday 10th November 2012
View Replies!

removing text string

I need to remove text string from the list of the numbers mentioned below: 080829-7_A 070529-5_c 080824-7_O 070405_6_p The output will be : 080829-7 070529-5 080824-7 070405-6 Any idea is highly appreciated....
VIEWS ON THIS POST

91

Posted on:

Sunday 11th November 2012
View Replies!

Cathing several potential errors?

if i do try: something except TypeError, IndexError: pass only the first error will get caught. I dont want to use Exception and catch all errors, but just 2. how can i do that...
VIEWS ON THIS POST

122

Posted on:

Sunday 11th November 2012
View Replies!

Re: Static memory allocation in Python

On Jun 17, 2008, at 2:34 PM, Eduardo Henrique Tessarioli wrote: > > > I am running a very simple python application and I noted that the > memory allocation is something like 4,5M. > This is a problem ...
VIEWS ON THIS POST

119

Posted on:

Sunday 11th November 2012
View Replies!

Re: help

Take a look at django's built in pagination features: http://www.djangoproject.com/documen...generic_views/ http://www.djangoproject.com/documentation/pagination/ Also, take a look at the django specific mailing list. django-users@googlegroups.com Cheers, Cliff On Fri, 2008-05-30 at 12:59 +0000, ha bo wrote: > hi > i wanna paginate my ...
VIEWS ON THIS POST

102

Posted on:

Sunday 11th November 2012
View Replies!

How to print a unicode string?

I'd like to print out a unicode string. I'm running Python inside Emacs, which understands utf-8, so I want to force Python to send utf-8 to sys.stdout. From what I've googled, I think I need to set my locale. I ...
VIEWS ON THIS POST

55

Posted on:

Sunday 11th November 2012
View Replies!

Re: sqlite3 - adding tables and rows via parameters

Vlastimil Brom wrote: > > 2008/4/12, Steve Holden >: > > Vlastimil Brom wrote: > > Hi all, > > I would like to ask about the usage of sqlite3 in python, more > > specifically about a way ...
VIEWS ON THIS POST

60

Posted on:

Sunday 11th November 2012
View Replies!

Re: Converting a tuple to a list

Gabriel Ibanez wrote: > Hi all .. > > I'm trying to using the map function to convert a tuple to a list, without > success. > > I would like to have a lonely line that performs the same ...
VIEWS ON THIS POST

34

Posted on:

Sunday 11th November 2012
View Replies!

Python equivt of __FILE__ and __LINE__

Writing a quick and dirty assembler and want to give the user the location of an error. The "assembly language" is Python. If the user wants to generat some object code they write something like: Label(LoopLable) Load(R4) Dec() JNZ(LoopLabel) I ...
VIEWS ON THIS POST

35

Posted on:

Sunday 11th November 2012
View Replies!

regex and IGNORECASE

Hi all, I have a problem with regex , utf-8 chars and IGNORECASE >>> re.search(u'', u'qwrt', re.IGNORECASE) <_sre.SRE_Match object at 0x2aaaaed0c100> Here everything is ok. >>> re.search(u'', u'qwrt', re.IGNORECASE) Here that doesn't work. but: >>> print u''.upper() is it ...
VIEWS ON THIS POST

71

Posted on:

Monday 12th November 2012
View Replies!

Re: Binary search tree

On 11/13/07, Terry Reedy (tjreedy@udel.edu) wrote: >"Scott SA" wrote in message >news:r02010500-1049-7D029806915411DC919E001124DEBE0E@[192.168.69.99]... >| On 11/12/07, Scott SA (pydev@rscorp.ab.ca) wrote: >| I decided to test the speeds of the four methods: >| >| set_example >| s = set() >| for ...
VIEWS ON THIS POST

58

Posted on:

Monday 12th November 2012
View Replies!

ODBC links?

Lo' there. I'm a new user of Python, what I'm looking for is an easy way to create ODBC links to Access databases (obviously, Access isn't the best database out there I can use, but its easiest to just piece ...
VIEWS ON THIS POST

23

Posted on:

Monday 12th November 2012
View Replies!

Global dictionary or class variables

in an application I have to use some variables with fixed valuse. For example, I'm working with musical notes, so I have a global dictionary like this: natural_notes = {'C': 0, 'D': 2, 'E': 4 ....} This actually works ...
VIEWS ON THIS POST

34

Posted on:

Saturday 24th November 2012
View Replies!

Re: Python and Open Office

Greg, as an addition to what I already said to you, you can consider taking a look at oood from ERP5 project http://wiki.erp5.org/HowToUseOood OOOd (openoffice.org daemon) runs openoffice behind the scene, and allows you to interact with it via XML-RPC; ...
VIEWS ON THIS POST

25

Posted on:

Sunday 25th November 2012
View Replies!

Re: SocketServer max connections

On Mon, Aug 25, 2008 at 7:20 AM, Ken Seehart wrote: > I'm using SocketServer to implement a local server that serves comet > long-polling connections. > > How do I increase the maximum number of open connections Currently ...
VIEWS ON THIS POST

33

Posted on:

Sunday 25th November 2012
View Replies!

Re: Trying ZODB, background in Relational: mimic auto_increment?

On Thu, 14 Aug 2008 05:22:35 -0700 (PDT), Phillip B Oldham wrote: >Hi all. I'm playing with standalone ZODB at the moment trying to get a >better understanding of its use in applications. I come from a >PHP/MySQL background, ...
VIEWS ON THIS POST

71

Posted on:

Sunday 25th November 2012
View Replies!

bliptv.reader V1.0 released

I am pleased to announce Version 1.0 of bliptv.reader, a package for easy access to videos hosted on blip.tv. You can get it via PyPI: http://pypi.python.org/pypi/bliptv.reader What is bliptv.reader ---------------------- bliptv.reader is a Python wrapper around the API of video ...
VIEWS ON THIS POST

56

Posted on:

Sunday 25th November 2012
View Replies!

Re: Question about optimization

On Thu, 24 Jul 2008 17:19:41 -0400, Wei Hao wrote: >Hi: > >I'm pretty new to python and I have some optimization issues. I'll show you >the piece of code which is causing it, with pseudo-code before it and ...
VIEWS ON THIS POST

50

Posted on:

Sunday 25th November 2012
View Replies!

Re: a simple 'for' question

On Wed, 2008-07-09 at 00:00 -0400, Ben Keshet wrote: > oops, my mistake, actually it didn't work... > when I tried: > for x in folders: > print x # print the current folder > filename='Folder/%s/myfile.txt' %x > f=open(filename,'r') > ...
VIEWS ON THIS POST

39

Posted on:

Sunday 25th November 2012
View Replies!

Re: How to make py2.5 distutil to use VC2005?

On Wed, Jun 4, 2008 at 11:38 AM, \t\t\t wrote: > Well, IMO, the format of binary files generated by VC2003 and > VC2005 is compatible in most cases. Problem arise with the C runtime, not with object file ...
VIEWS ON THIS POST

28

Posted on:

Sunday 25th November 2012
View Replies!

Weird import problem

I have a directory structure like NS/dir1/file1.py NS/dir2/file2.py if in the python shell I type import NS.dir1.file1 it works, however typing import NS.dir2.file2 fails with ImportError: No module named dir2.file2 Any ideas what could go wrong Directory permissions seem to ...
VIEWS ON THIS POST

60

Posted on:

Sunday 25th November 2012
View Replies!

Problems with Cheese Shop

Hallchen! How can I authorise to the Python Cheese Shop in order to use setup.py upload Currently, I get Upload failed (401): You must be identified to edit package information
VIEWS ON THIS POST

27

Posted on:

Sunday 25th November 2012
View Replies!

Re: argument to python cgi script

En Wed, 09 Apr 2008 11:14:33 -0300, syed mehdi escribi: > Hi Guys, > If someone can help me in telling how can i pass arguments to python cgi > script then that will be good. > like if ...
VIEWS ON THIS POST

38

Posted on:

Sunday 25th November 2012
View Replies!

Convert binary file

, Specifically, I'm trying to convert the Internet Explorer history file (index.dat) into a readable format. Anyone done something similar or know of any functions that may help with such a task I'm not sure exactly what kind of file ...
VIEWS ON THIS POST

45

Posted on:

Sunday 25th November 2012
View Replies!

Exception or not

Suppose you have some HTML forms which you would like to validate. Every field can have different errors. For example, this are the forms: username password etc And you want to validate them with some class. Is this good pattern: ...
VIEWS ON THIS POST

38

Posted on:

Sunday 25th November 2012
View Replies!

Function Overloading and Python

I have a personal project that has an elegant solution that requires both true multiple inheritance of classes (which pretty much limits my language choices to C++ and Python) and type-based function overloading. Now, while this makes it sound like ...
VIEWS ON THIS POST

19

Posted on:

Sunday 25th November 2012
View Replies!

Python too complex ?!?!?!

Had a unsettling conversation with a CS instructor that teaches at local high schools and the community college. This person is a long-term Linux/C/Python programmer, but he claims that the install, config, and library models for C# have proved to ...
VIEWS ON THIS POST

27

Posted on:

Monday 26th November 2012
View Replies!

=?ISO-8859-1?Q?Hi_I_am_anuusha_21years_of_student..._find_your_love?==?ISO-8859-1?Q?r_here_www.loverguru.blogspot.com?=

Hi I am anuusha 21years of student... find your lover here www.loverguru.blogspot.com...
VIEWS ON THIS POST

79

Posted on:

Monday 26th November 2012
View Replies!

List permutations?

How would you go about doing list permutations in python I've seen permutations in C++, C, and Java. but I wanna see what it looks like in python
VIEWS ON THIS POST

37

Posted on:

Tuesday 27th November 2012
View Replies!

The Demise of lambda, map, filter and reduce

But, on the other hand: (Toggle Plain Text) [i * i for i in l if i % 2 == 0] [i * i for i in l if i % 2 == 0]
VIEWS ON THIS POST

33

Posted on:

Tuesday 27th November 2012
View Replies!

Limit the size of wxListCtrl in wxpython

I want to limit the size of a list control box. Let us take the following code: (Toggle Plain Text) import wx class Students(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size=(380, 230)) hbox = wx.BoxSizer(wx.HORIZONTAL) panel = wx.Panel(self, -1) self.list = wx.ListCtrl(panel, -1, style=wx.LC_REPORT) self.list.InsertColumn(0, 'name') self.list.InsertColumn(1, 'age') hbox.Add(self.list, 1,wx.EXPAND) panel.SetSizer(hbox) self.Centre() self.Show(True) app = wx.App() Students(None, -1, 'studs') app.MainLoop() import wx class Students(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size=(380, 230)) hbox = wx.BoxSizer(wx.HORIZONTAL) panel = wx.Panel(self, -1) self.list = wx.ListCtrl(panel, -1, style=wx.LC_REPORT) self.list.InsertColumn(0, 'name') self.list.InsertColumn(1, 'age') hbox.Add(self.list, 1,wx.EXPAND) panel.SetSizer(hbox) self.Centre() self.Show(True) app = wx.App() Students(None, -1, 'studs') app.MainLoop()
VIEWS ON THIS POST

42

Posted on:

Wednesday 28th November 2012
View Replies!

New Search Engine?

What language would you use to create a search engine Also, how difficult would it be to develop a site similar to that of Yelp
VIEWS ON THIS POST

33

Posted on:

Wednesday 28th November 2012
View Replies!

Good tutorials for python

Hi I was wondering if anybody had any suggestions for books/online tutorials for python I am currently using 'learning python' by mark lutz but i don't really like it. I was also wondering how you like to type code ex: text editor than python interpreter or an IDE.
VIEWS ON THIS POST

74

Posted on:

Friday 28th December 2012
View Replies!

My journey through programming

While must be followed by a non-optional expression. The expression given by the empty tuple () in while(): evaluates to False, so the loop never begins. If you want an infinite loop, then use while True:. It may make more sense to make your controls function return the operation that will occur (as opposed to printing it). in is not a function. It is a keyword. Using it like in("back", "Back", "b", "B") gives readers the impression that it's a function, even though Python knows to interpret it as a keyword in followed by a tuple (..., ...). Add a space in between. You can accept both lower and upper case easily by modifying the input domain. That is, 'lower' the input, and then compare it to lower case strings.
VIEWS ON THIS POST

41

Posted on:

Friday 28th December 2012
View Replies!

why are classes created

hello ,i am a newbie to programming learning python as my 1st language.1why are classes created.2similarly after creating a class they define something called methods.why are methods created when we can create functions.3 what exactly is this creating a instance/object mean why is this done.
VIEWS ON THIS POST

60

Posted on:

Friday 28th December 2012
View Replies!

Book Progression!?!?

, I just went out and bought my first Python books. What do you think about this book progression from a learning stand point of new programmer. Learning Python Second Edition by Lutz then Programming Python Third Edition by Lutz and then having the Python Pocket Reference Third Edition. One thing that slightly worries me is that Learning python is on 2.3 and the reference manual is on 2.4 while 2.5 is out :/ Perhaps it would of been wise to wait on the Pocket Reference for a new edition Anyways I have these books now, not sure on Borders return policies, but if I could get some recommendations or if these books serve me well then ill stick to them.
VIEWS ON THIS POST

57

Posted on:

Friday 28th December 2012
View Replies!