[Tutor] which way do I go?
Alan Gauld
alan.gauld at blueyonder.co.uk
Wed Oct 15 17:41:53 EDT 2003
> >>>sumdifference (3, 9)
>
> my result should be 30
> this comes from adding the numbers 4+5+6+7+8=30
Look at how to define functions.
You need a function called sumdifference that takes two arguments,
therefore your definition has to have two parameters, lets call
them x and y.
You want to add all the values from x+1 to y-1.
Look at the range(x,y) function in Python, it generates numbers
in the range x to y-1 which is nearly what you want.
Also to add the numbers together you need to repeat the addition for
each numvber.
Look at the for command in Python.
In my tutor the relevant topics are:
Simple sequences
Looping
Functions and Modules
I hope thats enough of a starter along with the other comments.
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list