The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
What the hell is this?!?!
Discuss What the hell is this?!?! in the Python Programming forum on Dev Shed. What the hell is this?!?! Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 20th, 2013, 12:20 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 2
Time spent in forums: 19 m 29 sec
Reputation 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()
|

February 20th, 2013, 12:32 PM
|
 |
Contributing User
|
|
Join Date: Nov 2012
Location: Iran / France
|
|
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.
|

February 20th, 2013, 12:50 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 2
Time spent in forums: 19 m 29 sec
Reputation 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?
|

February 20th, 2013, 01:24 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 15
Time spent in forums: 1 h 54 m 19 sec
Reputation 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...
|

February 20th, 2013, 02:40 PM
|
 |
Contributing User
|
|
Join Date: Nov 2012
Location: Iran / France
|
|
Quote: | 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...ining-functions
Quote:
...
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|