CSC 120 L101 Practice Midterm #1
Instructor: Elizabeth Patitsas
February 4, 2015
Last name:
First name:
Your utorid:
Your lab section:
TUESDAY 3-5pm
or
5-7pm
(circle one)
You have 50 minutes to write the exam.
You are not permitted any aids, notes, book
CSC 120 L101 Midterm #1
Instructor: Elizabeth Patitsas
February 4, 2015
Last name:
First name:
Your utorid:
Your lab section:
TUESDAY 3-5pm
or
5-7pm
(circle one)
You have 50 minutes to write the exam.
You are not permitted any aids, notes, books, or cal
CSC120 Lecture 11 If Statements
1
The if statement
In everyday life, we often make decisions based on the current conditions.
If the weather is warm,
I wear shorts.
Otherwise,
I wear pants.
The same conditional process appears when writing code. To handle
CSC120 Lecture 8 - Indexing and Slicing Numpy Arrays
1
Indexing
Everything in a numpy array has an index. What will these lines of code do?
s = np.array([1, 2, 3])
s[0]
s[1:]
s[:]
s[-1:]
Negative numbers are used to reach the end of an array. For s, since
CSC120H Lab 1
1
Objectives
1. Practice using variables
2. Practice running and editing Python programs
3. Practice writing functions
4. Practice translating mathematical functions into Python ones
2
Marking
Every lab will be marked out of 4. Each lab will
CSC120H Lab 6
Objectives
1. Practice with iteration
2. Practice with strings
3. Practice with lists
4. Turtles turtles turtles
Preparation
Before doing this lab, you should be able to:
1. Write a for loop which traverses a range for example, write code th
CSC120H Lab 2
Objectives
1. Practice with helper functions
2. Practice writing docstrings, including doctests
3. Practice implementing functions
4. Practice debugging provided functions
5. Practice translating mathematical functions into Python ones
Marki
CSC 120H1S Practice Final Exam
Instructor: Elizabeth Patitsas; Term: Winter 2015
Last name:
First name:
Your utorid:
Student number:
You have 2 hours to write the exam.
You are not permitted any aids, notes, books, or calculators.
This exam is out of 50 p
CSC 120H1S Practice Final Exam
Instructor: Elizabeth Patitsas; Term: Winter 2014
Last name:
First name:
Your utorid:
Student number:
You have 3 hours to write the exam.
You are not permitted any aids, notes, books, or calculators.
This exam is out of 50 p
Midterm #1 sample solutions
1. def calendar_difference(year):
(int) -> int
Return the how far the year in the Gregorian calendar
is from the Julian calendar.
> calendar_difference(2014)
13
> calendar_difference(1614)
10
H = year / 100
return H - H / 4 - 2
CSC120 Lecture 15 Lists
1
Lists: Introduction and indexing
Earlier this term we saw numpy arrays, which allowed us to represent collections of numbers. However, arrays can only contain things of one particular type.
Lists are similar to arrays, but they c
CSC120 Lecture 14 String Methods
1
Methods
We have been using some string operators such as:
csc + 120
"hi" * 3
"ou" in "colour"
There are many more! so many, in fact, that there arent enough operator symbols for all of
them. Python denes these operators
CSC120 Lecture 13 Iterating over Strings
1
Strings
Python represents text as strings, which are sequences of characters. We have used some strings
already this term; in our next couple of lectures we will talk about them more in depth.
1.1
Basics
We dene
CSC120H Lab 7
Objectives
1. Practice with the os module
2. Practice with reading tab delimited les
Preparation
Before doing this lab, you should be able to:
1. Open les with numpys genfromtxt using multiple delimiters (comma, tab, etc)
2. Combine multiple
CSC120 Lecture 12 Logic Operators
1
1.1
Working with Booleans
Boolean variables
Suppose that snowing and sunny are of type bool. They can be either True or False.
snowing = False
sunny = True
temperature = -5
below_zero = temperature < 0
above_zero = temp
CSC120 Lecture 23 Lists
A list is a collection type in Python, and give us an alternative to arrays.
To create a list, enclose its contents in []s, and separate the entities with commas. For example:
my_list = [cat, dog, 1, 2.053, True]
As we can see, we
CSC120 Lecture 24 Paramater Passing and Raising/Catching Exceptions
In this lecture we will start by covering a few small things that will be helpful for your assignment,
then well focus on exceptions.
1
Functions are First Class
Review: what will this pr
CSC120H Lab 4
Objectives
1. Practice with le reading
2. Practice with numpy arrays, particularly ltering
3. Practice with if-statements
4. Introduction to discrete-event simulation
Marking
Every lab will be marked out of 4. Each lab will contain four item
CSC120H Lab 8
Objectives
1. Practice with sqlite
2. Practice selecting from tables using where
3. Practice performing joins
Preparation
Before doing this lab, you should be able to:
1. Write select statements in SQL, including select statements with where
CSC120 Lecture 3 Functions
So far we have been working in the console of Spyder, which allows us to execute lines of code one
by one. But what if we want to run multiple lines of code at a time? In this lecture we will use the
editor to write Python progr
CSC 120: Computer Science for the Sciences (R section)
Radford M. Neal, University of Toronto, 2015
http:/www.cs.utoronto.ca/radford/csc120/
Week 5
Environments
An R environment is a collection of variables and their current values.
The global environment
CSC 120: Computer Science for the Sciences (R section)
Radford M. Neal, University of Toronto, 2015
http:/www.cs.utoronto.ca/radford/csc120/
Week 7
Adding Attributes to R Objects
An R object can have one or more attributes, that record extra information.
CSC 120: Computer Science for the Sciences (R section)
Radford M. Neal, University of Toronto, 2015
http:/www.cs.utoronto.ca/radford/csc120/
Week 8
Names and NA Two R Features for Statistics
R is a general purpose programming language. You can write all s
CSC 120: Computer Science for the Sciences (R section)
Radford M. Neal, University of Toronto, 2015
http:/www.cs.utoronto.ca/radford/csc120/
Week 3
Making Functions Do Dierent Things, Using if
When you call a function with dierent values for its arguments
CSC 120: Computer Science for the Sciences (R section)
Radford M. Neal, University of Toronto, 2015
http:/www.cs.utoronto.ca/radford/csc120/
Week 10
Operations on Vectors
Weve seen before that R can do many operations on entire vectors (or matrices),
not
CSC 120: Computer Science for the Sciences (R section)
Radford M. Neal, University of Toronto, 2015
http:/www.cs.utoronto.ca/radford/csc120/
Week 12
Statistical Facilities in R
In this course, weve mostly looked at R as a programming language, and at
gene
CSC 120: Computer Science for the Sciences (R section)
Radford M. Neal, University of Toronto, 2015
http:/www.cs.utoronto.ca/radford/csc120/
Week 11
Another Use for Classes Factors
Recall that how R handles an object can be changed by giving it a class
at
CSC 120: Computer Science for the Sciences (R section)
Radford M. Neal, University of Toronto, 2015
http:/www.cs.utoronto.ca/radford/csc120/
Week 9
Random Numbers and Their Uses
Random variation is a big part of what statistics is about. So its natural th
def remove_letter(s, letter):
' (str, str) -> str
Return a string identical to s, but with all
instances of the given letter removed.
Requirement: Do not use the replace method. You must use a for loop.
> remove_letter('poodle','e')
'poodl'
> remove_lette
def get_letter_grade(percentage):
"
(number) -> str
Return the letter grade for the given percentage grade.
Assume that percentage is a value between 0 and 100.
>
'F'
>
'C'
>
'D'
>
'A'
>
'B'
"
get_letter_grade(20)
get_letter_grade(65)
get_letter_grade(52)
Fall 2016
Course Syllabus
This sheet summarizes information for the course CSC 120 H1F (Computer Science for the
Sciences) during the Fall 2016 term on the St. George campus at the University of Toronto.
Please consult the course website for all of the in