Main.Lab3 History

Hide minor edits - Show changes to markup

February 07, 2013, at 02:32 PM MST by 129.82.44.223 -
Changed lines 4-5 from:
  • Practice iteration structures: while and for
to:
  • Practice while loops
Changed line 24 from:

Write a function called factorial(n) that computes n!.

to:

Write a function called factorial(n) that returns n!.

Changed lines 26-27 from:

Write a version that uses a while structure, and a version that uses a for loop.

to:
Changed line 31 from:

that sums the even numbers that are less or equal to n.

to:

that returns the sum of the even numbers that are less or equal to n.

February 06, 2010, at 04:32 PM MST by 71.196.160.210 -
Added lines 5-20:

Print numbers

Write a function called print_numbers(n) that prints a comma-separated list of the numbers 1 through n on a single line. So for example, print_numbers(5) should produce the output

1, 2, 3, 4, 5

Note that the print command starts a new line every time it is issued. To prevent it starting a new line do

print something,

The comma at the end tells it not to start a new line. To print a number followed by a string you can do the following:

print str(2) + "string"

February 06, 2010, at 04:25 PM MST by 71.196.160.210 -
Changed lines 6-7 from:

Factorial

to:

Factorial

Changed line 12 from:

Summing even numbers

to:

Summing even numbers

February 06, 2010, at 04:25 PM MST by 71.196.160.210 -
Added lines 1-16:

Lab 3

Objectives:

  • Practice iteration structures: while and for

Factorial

Write a function called factorial(n) that computes n!. Recall that n! = n (n-1) ... 1, and that 0! = 1. Write a version that uses a while structure, and a version that uses a for loop.

Summing even numbers

Write a function called sum_even(n) that sums the even numbers that are less or equal to n.