[Edu-sig] docs.tutorial function example - too complicated
Jurgis Pralgauskis
jurgis.pralgauskis at gmail.com
Sun Dec 16 00:52:31 CET 2012
Hi,
currently more and more schools are trying Py,
so studens read tutorial docs from time to time...
and one of main programming (architecture) subjects starts with quite
a mathematical and unpractical example..
http://docs.python.org/3/tutorial/controlflow.html#defining-functions
It's like teaching to pilot airplane, prior to bicycle and car :)
I'd propose some simple examples at first:
like in http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_3/Defining_Functions
or http://www.cplusplus.com/doc/tutorial/functions/
def greeting( person ):
print( "Hello", person )
def add(a, b):
result = a+b
return result
z = add(3, 5)
# could aslso graphically show, how data (arguments/results) travel
# as in C++ example
def absolute_value(n):
if n < 0:
n = -n
return n
def count_down( n ):
while n > 0:
print( n )
n = n-1
def average( mylist ):
return sum(mylist) / len(mylist)
def decide_on_scholarship( marks ):
avg = average(marks)
if avg > 9.5:
return 1000
elif avg >= 8:
return 200
else:
return 0
Maybe there is some other list, where it would be more appropriate to
discuss this?
--
Jurgis Pralgauskis
tel: 8-616 77613;
Don't worry, be happy and make things better ;)
http://galvosukykla.lt
More information about the Edu-sig
mailing list