Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Mar 3rd, 2005, 4:01 PM   #11
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
Quote:
Originally Posted by arod199113
so "def" gives another name to a variable?
:o I give up...
Fred is offline   Reply With Quote
Old Mar 3rd, 2005, 4:12 PM   #12
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
ok....
'def' assigns a certain process to a name. Just like naming this 'foot in front of the other foot' walking. You just say def and the the name. The you press ':' this sign and press enter. And the you kust tell the computer what to do, everytime you say the name.
The easiest example of them all:
def HelloWorld():
   print 'Hello World'

And that is it. So now, everytime in your program, whwn you type 'HelloWorld', a message appears, saying 'Hello World'...
Not that hard, is it???
Hope this helps
Fred
Fred is offline   Reply With Quote
Old Mar 3rd, 2005, 4:51 PM   #13
arod199113
Programmer
 
arod199113's Avatar
 
Join Date: Feb 2005
Posts: 86
Rep Power: 0 arod199113 is an unknown quantity at this point
ok
that helped
you said it in simpler terms
but are the "()" necessary at the end?
and what is the point of putting something in the bracket?
arod199113 is offline   Reply With Quote
Old Mar 3rd, 2005, 5:06 PM   #14
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
They are necessary. They are used to pass so called 'arguments'. That is the information, the function needs to wrok. To go back to our 'HelloWorld' function:
def HelloWorld(n): #n is a namespace for an argument
   print 'Hello World' * n
So, now when you type:
HelloWorld(1)
the program prints the message once.
If you type:
HelloWorld(2)
The you get the message twice.

Or if we use our other example and define the function 'walk', you could give the computer the number of steps to go.
Fred is offline   Reply With Quote
Old Mar 3rd, 2005, 6:06 PM   #15
arod199113
Programmer
 
arod199113's Avatar
 
Join Date: Feb 2005
Posts: 86
Rep Power: 0 arod199113 is an unknown quantity at this point
you have to explain it to me a little simpler
what does
print 'Hello World' * n
do?
it multiplies 'helloworld' by n but what is "n"?

Last edited by arod199113; Mar 3rd, 2005 at 6:10 PM.
arod199113 is offline   Reply With Quote
Old Mar 3rd, 2005, 7:57 PM   #16
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
Did you take math in school???
n can be any natural number. Meaning, that it can be any number without desmos or fractions which is bigger than 0.
In other words, n is a variable.
It is the number, which you put into the brackets, when you call the function (when you apply the prcess).
I strongly advise reading this tutorial:
http://www.ibiblio.org/obp/thinkCSpy/chap03.htm (functions in general)
and
http://www.ibiblio.org/obp/thinkCSpy/chap05.htm (useful functions and how to apply them)
Fred is offline   Reply With Quote
Old Mar 3rd, 2005, 9:39 PM   #17
arod199113
Programmer
 
arod199113's Avatar
 
Join Date: Feb 2005
Posts: 86
Rep Power: 0 arod199113 is an unknown quantity at this point
i understand math
i just dont cant understand functions in python
math != python
math <= python
arod199113 is offline   Reply With Quote
Reply

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:05 PM.

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