Lecture Notes for CPSC 121 Fall 2012: While Loop Exercises and Function Computation, Study notes of Computer Science

These lecture notes cover the fall 2012 semester of cpsc 121, focusing on while loop exercises and the computation of a function using both for and while loops. Students are encouraged to review quiz and exam questions, and to read chapter 7 of the textbook by s. Bowers.

Typology: Study notes

2012/2013

Uploaded on 09/28/2013

noob
noob 🇮🇳

4.4

(25)

105 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture Notes CPSC 121 (Fall 2012)
Today ...
Go over quiz and exam questions
While loop exercises
Reading
Ch 7
S. Bowers 1 of 2
pf2

Partial preview of the text

Download Lecture Notes for CPSC 121 Fall 2012: While Loop Exercises and Function Computation and more Study notes Computer Science in PDF only on Docsity!

Lecture Notes CPSC 121 (Fall 2012)

Today ...

  • Go over quiz and exam questions
  • While loop exercises

Reading

  • Ch 7

S. Bowers 1 of 2

Lecture Notes CPSC 121 (Fall 2012)

While versus for loops

Q: What does this function compute?

def f(n): r = 1 for i in range(1, n+1): r = r * i return r

  • Returns the product of the first n integers

Q: How can we write this using a while loop?

def f(n): r = 1 i = 1 while i <= n: r = r * i i = i + 1 return r

S. Bowers 2 of 2