2/11/14, 1:52 PM
Lecture Notes on 16 Sep 2013
Problem: Prompt the user to enter 3 numbers and print
the numbers in ascending order. Write pseudo code for
the algorithm
# Read the numbers and store the
2/11/14, 1:53 PM
Lecture Notes on 25 Nov 2013
# keeps only letters and removes everything else
def filter_string (st):
s = '
for ch in st:
if (ch >= 'a') and (ch <= 'z'):
s += ch
else:
s += ' '
return
2/11/14, 1:53 PM
Lecture Notes on 22 Nov 2013
# keeps only letters and removes everything else
def filter_string (st):
s = '
for ch in st:
if (ch >= 'a') and (ch <= 'z'):
s += ch
else:
s += ' '
return
2/11/14, 1:53 PM
Lecture Notes for 01 Nov 2013
Some Sample Questions for Test 2
1. Write a function that sums the following series to the nth
term
S(n) = 1 / (1 * 2) + 1 / (2 * 3) + . + 1 / (n + 1) *
2/11/14, 1:53 PM
Lecture Notes on 18 Nov 2013
def scalar_product (a, b):
sum = 0
for i in range (len(a):
sum += a[i] * b[i]
return sum
def seq_search (a, x):
index = []
for i in range (len(a):
if (x =
2/11/14, 1:53 PM
Lecture Notes on 13 Nov 2013
Solution to Test 2 Problems
# Ques 1
def p (n):
if (n = 0):
return 0
else:
return (2 + 3 * p (n - 1)
def p_iter (n):
sum = 0
for i in range (n):
sum = 2 +
2/11/14, 1:53 PM
Lecture Notes 11 Nov 2013
def find_max (b):
max = b[0][0]
for row in b:
for col in row:
if (col > max):
max = col
return max
def find_min (b):
min = b[0][0]
for row in b:
for col in r
2/11/14, 1:52 PM
Lecture Notes on 04 Oct 2013
def main():
# Sum numbers 1 through 10
sum = 0
counter = 1
while (counter <= 10):
sum = sum + counter
counter = counter + 1
print (sum)
# Version 1: Deter
2/11/14, 1:52 PM
Lecture Notes on 07 Oct 2013
# Outline of Assignment 5
def main():
# Prompt the user to enter a positive number
n = int (input ('Enter a positive number: ')
# Prompt again if the numb
2/11/14, 1:52 PM
Lecture Notes on 27 Sep 2013
* Test 1 on 2 Oct 2013 - in class and closed book
No multiple choice questions
Number conversions
Write code or interpret code
Study guide posted
* Assign
2/11/14, 1:52 PM
Lecture Notes on 23 Sep 2013
Recapitulate What We Have Done So Far:
* We see the world in binary
* Number conversions: decimal to binary, octal, hexadecimal
and vice versa
* Structure
History of Computing
2/11/14, 1:51 PM
History of Computing
1. Earliest Traditions
Man need to keep track of things - whether it was the number of things, the measure of distance, or weight, or
time. H
Algorithms
2/11/14, 1:51 PM
Algorithms
What is an algorithm?
A program is a set of instructions that a computer executes to achieve a certain desired effect - perform a
calculation, render a picture,
Data Structure
2/11/14, 1:52 PM
Tuple
A tuple is like a list. It is an ordered sequence but unlike a list it is immutable. It is created by specifying the
items in the tuple within parentheses and sep
2/11/14, 1:53 PM
Lecture Notes on 15 Nov 2013
# Outline of Word Search
def check_columns (string_cols, word):
# initialize row_num and col_num to zero
# create rev_word that is the reverse of the word