menu COMPSCI 2120/9642/DIGIHUM 2220 1.0 documentation

Activity 2

_images/sum_numbers.png

What you need to do

Write a function intsum(n) that takes a single integer n as a parameter and returns the sum of all of the numbers between 1 and n (i.e. 1 + 2 + ... + n-1 + n). Call the function for n = 10. Your function must use a while loop.

Trace through your function for the call intsum(10) using a trace table. Include the table in your submission.

Bonus: you get 1 bonus point if your python program prints the table automatically (click this link for help).

Clarification on the bonus mark

To get the bonus, you’ll need to print the table automatically (i.e. for a function call for intsum(12), the corresponding table would be printed). You will not get the bonus mark if you manually insert the table values.

What to submit (in zipped folder)

  1. Your python file (activity2.py)

  2. A text file with your output (output.txt)

  3. Your trace table (however you’d like, but for the bonus it will need to be in your output as a result of being automatically generated from your python script)