Class Notes (905,093)
CA (538,354)
UTSG (45,721)
CSC (765)
CSC108H1 (113)
Diane (4)
Lecture

Notes

8 Pages
98 Views

Department
Computer Science
Course Code
CSC108H1
Professor
Diane

This preview shows pages 1-3. Sign up to view the full 8 pages of the document.
Pictures and Pixels
Thats what 1024 x 768
resolution means: 1024
pixels wide, 768 pixels high Pixel (0, 0) is upper left Pixel (1023, 0) is
upper right
Pixel (0, 767) is lower left Pixel (1023, 767) is lower right
Colour Representation
Colours: combinations of red, green, and blue
Each component has intensity in range 0 - 255
Red: (255, 0, 0) Green: (0, 255, 0) Blue: (0, 0, 255)
White: (255, 255, 255) Black: (0, 0, 0)
>>> # Python also has functions, like in math.
>>> max(5, 99, -2, 12)
99
>>> # This function asks the user to choose a file.
>>> media.choose_file()
>>> # I can't do anything with that file unless I remember it somewhere.
>>> # Fortunately, Python has variables (kind of like in math).
>>> x = 12
>>> y = 0
>>> z = 42
>>> max(x, y, z)
42
>>> # So I can use a variable to remember the filename the user chooses.
>>> filename = media.choose_file()
>>> # Python has remembered it.
>>> filename
u'/h/u1/dianeh/women/instructors.png'
>>> # Now I can ask Python to read the image stored in the file of that
>>> # name, and load it into memory.
>>> pic = media.load_picture(filename)
>>> # And now I can ask it to show the picture on the screen.
>>> media.show(pic)
import media
if __name__ == "__main__":
filename = media.choose_file()
pic = media.load_picture(filename)
media.show(pic)
filename = media.choose_file()
pic = media.load_picture(filename)
media.show(pic)
blue = media.get_blue(pixel)
new_blue = int(blue * 0.7)
media.set_blue (pixel, new_blue)
#For sunset do the same to the green pixels.
www.notesolution.com
green = media.get_green(pixel)
new_green = int(green * 0.7)
media.set_green (pixel, new_green)
media.show(pic)
>>> 4 / 0
Traceback (most recent call last):
File "<string>", line 1, in <string>
ZeroDivisionError: integer division or modulo by zero
>>> 4 % 0
Traceback (most recent call last):
File "<string>", line 1, in <string>
ZeroDivisionError: integer division or modulo by zero
>>> # Functions
>>> min(9, -17)
-17
>>> max(9, -17, 22, 0, -44, 193, 9)
193
>>> abs(-17)
17
>>> abs(-7 * 23 - 45)
206
# function "dir" gives you a directory or listing of available
functions.
>>> dir(__builtins__)
Python Types
Every Python value has a
type that describes what
sort of value it is
Built-in function type
will tell you the type of
an expression
English Python
integer int
real number float
picture Picture
pixel Pixel
colour Color
string of letters str
Must start with a letter (or underscore).
Can include letters, digits, and underscores, but
nothing else.
And case matters, by the way.
www.notesolution.com
age = 11
aGe # Error! This is not defined.
Valid: _moo_cow, cep3, I_LIKE_TRASH
Invalid: 49ers, @home
Python expressions:
f(x+3)
98.6 * 2
Each refers to a value.
Python sentences (“statements):
temperature = 98.6
return (x + y + z) / 3
Python statements are always commands to do something (never statements of fact,
or
questions).
raw_input is a function that:
prompts the user to type something by printing the string you give it (if you give it one),
waits until the user hits the enter/return key,
returns a string containing whatever the user typed before hitting enter/return.
So the value of a raw_input expression is what the user entered.
Calledraw because its untreated: nothing has been done to it.
To show output in the editor, use print. Example:
print “Hello!”
mark1 = raw_input(“First mark: “)
mark2 = raw_input(“Second mark: ”)
print “The average is”, average(mark1, mark2)
Comma is for printing lists of items, separated by blanks.
>>> # A new type: Boolean
>>> # Named after a philosopher/logician called Boole.
>>>
>>> # If-statements need a "condition": something that's either true or false.
>>> my_average = 73.12
>>> my_average > 90
False
>>> if my_average > 90:
... print "wow!"
...
>>> # "my_average > 90" was a boolean expression; it's value is either True or False.
>>> # ">" was a boolean operator: compares two things and gives back either True or False.
>>> # To compare for equality, use a DOUBLE equals sign
>>> 3 != 4
True
>>> # Next class: how to combine boolean expressions.
www.notesolution.com

Loved by over 2.2 million students

Over 90% improved by at least one letter grade.

Leah — University of Toronto

OneClass has been such a huge help in my studies at UofT especially since I am a transfer student. OneClass is the study buddy I never had before and definitely gives me the extra push to get from a B to an A!

Leah — University of Toronto
Saarim — University of Michigan

Balancing social life With academics can be difficult, that is why I'm so glad that OneClass is out there where I can find the top notes for all of my classes. Now I can be the all-star student I want to be.

Saarim — University of Michigan
Jenna — University of Wisconsin

As a college student living on a college budget, I love how easy it is to earn gift cards just by submitting my notes.

Jenna — University of Wisconsin
Anne — University of California

OneClass has allowed me to catch up with my most difficult course! #lifesaver

Anne — University of California
Description
Pictures and Pixels Thats what 1024 x 768 resolution means: 1024 pixels wide, 768 pixels high Pixel (0, 0) is upper left Pixel (1023, 0) is upper right Pixel (0, 767) is lower left Pixel (1023, 767) is lower right Colour Representation Colours: combinations of red, green, and blue Each component has intensity in range 0 - 255 Red: (255, 0, 0) Green: (0, 255, 0) Blue: (0, 0, 255) White: (255, 255, 255) Black: (0, 0, 0) >>> # Python also has functions, like in math. >>> max(5, 99, -2, 12) 99 >>> # This function asks the user to choose a file. >>> media.choose_file() >>> # I cant do anything with that file unless I remember it somewhere. >>> # Fortunately, Python has variables (kind of like in math). >>> x = 12 >>> y = 0 >>> z = 42 >>> max(x, y, z) 42 >>> # So I can use a variable to remember the filename the user chooses. >>> filename = media.choose_file() >>> # Python has remembered it. >>> filename uhu1dianehwomeninstructors.png >>> # Now I can ask Python to read the image stored in the file of that >>> # name, and load it into memory. >>> pic = media.load_picture(filename) >>> # And now I can ask it to show the picture on the screen. >>> media.show(pic) import media if __name__ == __main__: filename = media.choose_file() pic = media.load_picture(filename) media.show(pic) filename = media.choose_file() pic = media.load_picture(filename) media.show(pic) blue = media.get_blue(pixel) new_blue = int(blue * 0.7) media.set_blue (pixel, new_blue) #For sunset do the same to the green pixels. www.notesolution.com
More Less
Unlock Document


Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

Unlock Document
You're Reading a Preview

Unlock to view full version

Unlock Document

Log In


OR

Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit