### Thread: What the hell is this?!?!

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2013
Posts
2
Rep Power
0

#### What the hell is this?!?!

Why the freakin hell won't this program work?

Code:
```# This program will prompt the user to enter 2 scores and calculate the average.

def getScores():
score1 = float(input("Enter the first score: "))
score2 = float(input("Enter the second score: "))
average = calcAverage(score1, score2)
print ("The average is: ", average)

def calcAverage(score1, score2):
average = (score1+score2)/2

def main():
getScores()
main()```
2. Because your average function doesn't return the average value (no return statement explicitly written in the function = return None), it should be something like this:

Code:
```def calcAverage(score1, score2):
return (score1+score2)/2```
The title of the topics created on this forum are used for those who do search before creating a new topic, so obviously, the title must somehow reflect what the topic is about.

Reading your topic title " What the hell is this?!?!" doesn't seem to conform to this best practice rule.

Regards,
Dariyoosh
Last edited by dariyoosh; February 20th, 2013 at 12:41 PM.
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2013
Posts
2
Rep Power
0
Thanks for the help. However, if I may ask, what exactly is a return statement and when would I use a return statement?
4. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2013
Posts
15
Rep Power
0
I am pretty sure the return statement calls on the function, while a print will produce the text. Somebody correct me if I am wrong...
5. Originally Posted by Th3C00lk1d
Thanks for the help. However, if I may ask, what exactly is a return statement and when would I use a return statement?
According to Python (3) online tutorial
http://docs.python.org/3.0/tutorial/...ning-functions
...
The return statement returns with a value from a function. return without an expression argument returns None. Falling off the end of a function also returns None
...
For example, let's say you define a function that takes as parameters two integers and calculates their product.

The mathematical syntax would be something like this:

productFun(x,y) = x * y

In python you write

Code:
```def productFun(x, y):
return x * y```
So thanks to the return statement, I may later write elsewhere in my code, for example:

Code:
```. . .
# so var will receive the value of 12 * 10 returned by the return statement of the function
var = productFun(12,  10)```

Regards,
Dariyoosh