![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programmer
Join Date: Feb 2005
Posts: 86
Rep Power: 0
![]() |
where would the file "apple" have to be saved?
|
|
|
|
|
|
#12 | |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Quote:
[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] |
|
|
|
|
|
|
#13 |
|
Programmer
Join Date: Feb 2005
Posts: 86
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#14 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
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] |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|