[Tutor] how to define a function with multple parameters
Alan Gauld
alan.gauld at btinternet.com
Wed Sep 23 01:45:30 CEST 2009
<shellcom3 at juno.com> wrote
>I want to know how to use multiple parameters for 1 function
Do you by any chance come from a Visual Basic background?
> def display(message):
> print message
>
> def rate_score():
> score = rate_score
This does nothing. It assigns the function rate_score to a local
variable which is immediately thrown away.
I suspect you wanted to "return" the score? Except you
don't assign a value to score, you assign the same function.
So I'm a bit confused over what you are trying to do.
> if rate_score <= 999:
This compares a function object, rate_score, to a number
which does not make sense. Even if rate_score returned
a value you need to provide parentheses to call the function.
Like this:
if rate_score() <= 99:
> elif rate_score <= 10000:
Same again
> elif rate_score >= 10000:
and again
> raw_input("Please type in your score")
And here you are again not storing the value anywhere.
I suspect you also want to convert it to a number so you
probably want:
score = int( raw_input("Please type your score ") )
> print "here's your score", rate_score
Again you are using the function object not a value.
You want to use whatever variable you choose to store the score in.
> rate_score()
Despite the subject of your email I think you need to go
back to the fundamentals of writing and using Python functions.
You obviously missed something fundamental first time around.
Try the Functions and Modules topic in my tutorial as an
alternative source of info...
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list