Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Feb 10th, 2005, 3:17 PM   #11
arod199113
Programmer
 
arod199113's Avatar
 
Join Date: Feb 2005
Posts: 86
Rep Power: 0 arod199113 is an unknown quantity at this point
where would the file "apple" have to be saved?
arod199113 is offline   Reply With Quote
Old Feb 10th, 2005, 7:20 PM   #12
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

Quote:
Originally Posted by arod199113
where would the file "apple" have to be saved?
Let's do this, type in the code in your IDE and save it as apple.py in your working folder, perhaps D:\Python23\Atest
[php]
# ... save this code as apple.py ...

# this function shows the result, does not return it
def PieCookingStatus(CookingTime):
if CookingTime < 30:
print "Still cooking!"
elif CookingTime <= 40:
print "Almost done!"
else:
print "Take pie out of the oven!"

# this function returns a value
def PiePercentCooked(CookingTime):
return 100*CookingTime/40
[/php]
Then type in this code and save it as appletest.py in the same working folder. Now run this test program.
[php]
# ... save this code as appletest.py and run it to
# test the module apple.py ...

import apple

# check the apple pie in the oven after specified number of minutes
MinutesCooking = 45
apple.PieCookingStatus(MinutesCooking)
print "Pie is %d percent cooked." % apple.PiePercentCooked(MinutesCooking);
[/php]
Dietrich is offline   Reply With Quote
Old Feb 10th, 2005, 8: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
i appreciate your help but i still dont understand it
probably because i never understood the "def" function

cause in the tutorial it was like:

a = 23
b = -23

def my_abs(num):
if num < 0:
num = -num
return num

if my_abs(a) == my_abs(b):
print "The absolute values of", a,"and",b,"are equal"
else:
print "The absolute values of a and b are different"


i understood what the program did
i just never understood what the define function did
arod199113 is offline   Reply With Quote
Old Feb 11th, 2005, 1:18 AM   #14
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
def is not a function, it is a keyword that tells you that what follows is the name of a function and its list of arguments in ()
[php]
# the function my_abs takes the argument num, processes it and returns the result
def my_abs(num):
if num < 0:
num = -num
return num

# you call it like this
x = my_abs(-99)
# the result would be x = 99
[/php]
Dietrich 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:03 AM.

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