"
L=[5,6,7,8,9]
L[1:4] = [11,12,13,14]
L[1:5] = []
L[1:1] = [3,2,1]
L[:3]
L[0:]
L[:]
print L
"
L=[5,6],[7,8,9]
def clear(L,x):
for i in range(len(L):
for j in range(len(L[i]):
L[i][len(L[x])]
print L
clear(L, 0)
def noNegatives(vals):
result = []
for i in range(len(vals):
if vals[i] >= 0:
result = result + [vals[i]
return result
val = 1
for i in range(1000000):
if val< 1000000:
val = 2 * val
else:
print i
break
val = range(1000001)
def countthis(val):
count = 0
v
# October 6, 2014
def numEggs():
return 4
x = 3 + numEggs() #x = 7
def ave(grade1, grade2, grade3):
average = (grade1+grade2+grade3)/3
return average
#print ave(10,10,6)
def average(vals):
numOfInts = len(vals)
sum = 0
for x in vals:
sum += x
ave = sum/nu
#October 8, 2014
def contains3s(vals):
'
returns True if 3 is an item in vals and returns
False otherwise
'
result = False
for x in vals:
if x = 3:
result = True
return result
def contains3s(vals):
'
returns True if 3 is an item in vals and returns
False
CS151 Spring 2009 Lecture 37
Stephanie R Taylor
May 6, 2009
1
Recursion
A recursive function is a function that calls itself.
Recursion is the term used to refer to a use of recursive functions to solve a problem or
accomplish a task.
1.1
Using Recursion
CS151 Spring 2009 Lecture 36
Stephanie R Taylor
May 4, 2009
1
Recursion
A recursive function is a function that calls itself.
Recursion is the term used to refer to a use of recursive functions to solve a problem or
accomplish a task.
1.1
Mathematical Exa
CS151 Spring 2009 Lecture 34
Stephanie R Taylor
April 29, 2009
1
Bubble Gum Machine
We nished writing our bubble gum machine code. I have uploaded the code to Moodle and
wont include it here.
2
3D Turtle
The 3-D turtle uses a 3D- coordinate system in whic
CS151 Spring 2009 Lecture 29
Stephanie R Taylor
April 17, 2009
1
Administrative Topics
We take the quiz
Please come to the pizza dinner!
2
Object-Oriented Design Principles
Recall the four design principles of O-O design:
Modularity: making functional
CS151 Spring 2009 Lecture 28
Stephanie R Taylor
April 15, 2009
1
Object-Oriented Design Principles
Of the four chief OO design principles, we have covered two - modularity and encapsulation,
although we havent necessarily used those terms. Today, we are g
CS151 Spring 2009 Lecture 25
Stephanie R Taylor
April 8, 2009
1
Administrative Topics
Moodle was down for a bit yesterday, but it seems to have been up again by the time
I got home from the math dessert party last night.
Did everyone see my answers to y
CS151 Spring 2009 Lecture 25 Follow-Up
Stephanie R Taylor
April 8, 2009
1
Continuing with the Bouncing Balls
We continue from where we left o on Wed. We were initializing a Scene, which creates
an instance of Balls. We were in the midst of running the ini
CS151 Spring 2009 Lecture 24
Stephanie R Taylor
April 6, 2009
1
Some Denitions
A module is simply a collection of executable statements, function denitions,
and class denitions. Modules are used to organize code. When we program
using a procedural design,
CS151 Spring 2009 Lecture 23
Stephanie R Taylor
April 3, 2009
1
Administrative Topics
We take the quiz
2
From Verbs to Nouns
The projects (both in- and out-side of class) we have done so far have taken
into consideration both the nouns and verbs of the p
CS151Spring2009Lecture23Followup
QuestionsandAnswers
Below are a list of questions and Stephanies answers. This is meant to accompany the lecture
notes from Lectures 23 and 24 it is not a stand-alone document.
SelfandDotNotation
It is still unclear to me
CS151 Spring 2009 Lecture 22
Stephanie R Taylor
April 1, 2009
1
Administrative Topics
Quiz on Fri will be about L-systems
2
Review of Turtle Graphics
Recall that the turtle has a position and a heading. In general we make
the turtle drag a pen around the
CS151 Spring 2009 Lecture 21
Stephanie R Taylor
Mar 30, 2009
1
Administrative Topics
I am passing back projects 5 and 6 today
Tomorrow there is a talk in the math colloquium by a statistician who
works for Google.
2
Grammars
For formal languages, gramma
CS151 Spring 2009 Lecture 17
Stephanie R Taylor
Mar 13, 2009
1
Administrative Topics
Python syntax requires all code in a line of code (e.g. an assignment
statement) to be on a line in the le, unless you use the escape character
just before the newline.
CS151 Spring 2009 Lecture 16
Stephanie R Taylor
Mar 11, 2009
1
Administrative Topics
I will have oce hours today beginning at noon and ending by 4:30.
Brian Eastwoods talk is Thurs at 4:15 with refreshments at 3:45
The Turing Award was announced yester
CS151 Spring 2009 Lecture 15
Stephanie R Taylor
Mar 9, 2009
1
Administrative Topics
I will have oce hours today beginning at noon and ending around
4:30.
Moodle destroys the indentation of code I post in the homeworks. For
a more nicely formatted versio
CS151 Spring 2009 Lecture 12
Stephanie R Taylor
Mar 2, 2009
1
Administrative Topics
I am leaving for a conference tomorrow and will not return until this
weekend. Bruce will be teaching Wed and Fri.
I will be grading the projects on the plane and will g
CS151 Spring 2009 Lecture 11
Stephanie R Taylor
Feb 27, 2009
1
Administrative Topics
We take Quiz 3
When writing python code, it is customary to append the extension
.py to the lename. Please be sure to do so with your les. That way,
when I download the
CS151 Spring 2009 Lecture 10
Stephanie R Taylor
Feb 25, 2009
1
Administrative Topics
Pass back quizzes
Pass back projects
Pass back HW5
2
More about Functions and Variables
Recall the last two functions from Wednesday,
# s c a l e P i c s c a l e t h e
CS151 Spring 2009 Lecture 9
Stephanie R Taylor
Feb 23, 2009
1
Administrative Topics
You will get your quizzes back on Wed.
There is a talk tomorrow that may interest many of you.
2
Transforming a Picture
Recall the function we wrote on Friday:
# Functio
CS151 Spring 2009 Lecture 8
Stephanie R Taylor
Feb 20, 2009
1
Administrative Topics
Did you all see my tutorial about how to get pictures posted on the
wiki?
Time for Quiz 2
2
Images in JES
This week in lab you used JES - the Jython Environment for Stud
CS151 Spring 2009 Lecture 7
Stephanie R Taylor
Feb 18, 2009
1
Administrative Topics
I am almost done grading Assignment #1.
There will be no homework tonight! I am giving you a break.
2
Booleans
A Boolean value is either True or False. The name Boolean
CS151 Spring 2009 Lecture 6
Stephanie R Taylor
Feb 16, 2009
1
Administrative Topics
Quizzes and homeworks will be graded and returned soon.
I am about a 1/4 of the way through grading Assignment #1 and am
pleased. I will have the rest graded by Wed.
Qu
CS151 Spring 2009 Lecture 5
Stephanie R Taylor
Feb 13, 2009
1
Administrative Topics
To access your les on the le server
On a Mac, open the nder, press cmd-K, type smb:/ler/personal,
hit return, enter you password and it should get you to ler. Then
navig
CS151 Spring 2009 Lecture 4
Stephanie R Taylor
Feb 11, 2009
1
Administrative Topics
Sorry about the problem with Moodle. You can now resubmit homeworks you have already submitted.
I want to comment on case. There are dierent ASCII code for capital lette
CS151 Spring 2009 Lecture 3
Stephanie R Taylor
Feb 9, 2009
1
Administrative Topics
Does everyone have a project partner?
Moodle was down yesterday. Did you all get my message about the
instructions on the cs departments website.
There is a grader for t