Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 20th, 2013, 12:20 PM
Th3C00lk1d Th3C00lk1d is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 2 Th3C00lk1d User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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()

Reply With Quote
  #2  
Old February 20th, 2013, 12:32 PM
dariyoosh's Avatar
dariyoosh dariyoosh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Location: Iran / France
Posts: 132 dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 6 h 13 m 10 sec
Reputation Power: 133
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.

Reply With Quote
  #3  
Old February 20th, 2013, 12:50 PM
Th3C00lk1d Th3C00lk1d is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 2 Th3C00lk1d User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #4  
Old February 20th, 2013, 01:24 PM
PythonNewb PythonNewb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 15 PythonNewb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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...

Reply With Quote
  #5  
Old February 20th, 2013, 02:40 PM
dariyoosh's Avatar
dariyoosh dariyoosh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Location: Iran / France
Posts: 132 dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 6 h 13 m 10 sec
Reputation Power: 133
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > What the hell is this?!?!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap