Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Dec 7th, 2006, 9:32 AM   #1
m0rb1d
Newbie
 
Join Date: Nov 2006
Posts: 19
Rep Power: 0 m0rb1d is on a distinguished road
Defining a Function

Heh, I seem to be all over this forum, causing myself no end of confusion trying to find a language I can bear with. Given enough time I"ll find my niche, and only be in one forum; this is the goal anyway.

Furthermore, the same people keep answering my questions, so, as before, if you can keep your annoyance level to a minimum, I"ll get less abrasive eventually.

Anyway, looking over, yes, another online tutorial, I need a little clarification. I've come to the section on declaring functions, and the given example sort of throws me. It is as follows: ( with the text from the tutorial )

The program seems a little repetitive. (Programmers hate to repeat things (That's what computers are for aren't they?)) Fortunately Python allows you to create functions to remove duplication. Here is the rewritten example:

a = 23
b = -23

def my_abs(num):
    if num < 0:
        num = -num
    return num

if my_abs(a) == my_abs(b):
    print "The absolute values of", a,"and",b,"are equal"
else:
    print "The absolute values of a and b are different"

I understand what it's doing, but now the how of it. Is code with Python not sequential? What's causing the confusion is the

def my_abs(num):
   if num < 0:
       num = -num
   return num

I see nothing declaring what (num) is. Does it get the value from the

if my_abs(a) == my_abs(b):

Because, it seems, following the code line by line, that the program wouldn't know what to do with the if num < 0:.
m0rb1d is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling Maverik 6.2 (from C) megamind5005 C 16 May 3rd, 2006 5:41 PM
libraries matko C 1 Jan 22nd, 2006 2:12 PM
Php Postgresql Class Pizentios Show Off Your Open Source Projects 15 Jun 28th, 2005 9:55 AM
Jackpot game zorin Visual Basic 3 Jun 10th, 2005 1:19 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC