Class Notes (834,153)
Canada (508,381)
CSC108H1 (113)

september 21 notes

2 Pages
Unlock Document

Computer Science
Michelle Craig

 Expression vs. statements o English expression: “The Prime Minister’s wife”, “the recycling”, ”lunch”  Each refers to something o English sentences:  “the prime minster’s wife at pancakes”  take the recycling out, please”  is it time for lunch o Each states a fact  Python expression: f(x+3) 98.6*2 o Each refers to a value o Python sentences (“statements”) Temperature = 98.6 Return (x + y + z)/3 o Python statements are always commands to do something (never statements of fact or questions)  Type expression in shell  shell will evaluate the expression and give result and prints it >>> x = 7 >>> y = 34 >>> x + y / 2.0 24.0 # automatic print o If done in IDE 1. x = 7 2. y = 34 3. x + y / 2.0 [evaluate] # not syntax error; result not printed  In python, normally make full statements, ex. o assignment statements; def statements; if statements o but the shell lets you give just an expression, and it then shows you the value of the expression o so to show output in the shell, you can just give an expression o To show output in editor, use print. Ex. print “hello!” 1. x = 7 2. y = 34 3. x + y / 2.0 4. #the example above shows that just putting an expression doesn‟t print its value 5. 6. print “hello” 7. mark1 = raw_input(“First mark? \n”) # manual input; \n = new line 8. mark2 = raw_input(“Second mark? ”) 9. 10. print “mark1 was”, mark1 #gives “mark 1 was (user inputted data)” 11. print “the average is”, float(mark1 + mark 2) / 2.0 12. #cast to float b/c input data might be int; “comma” gives a space o Two print statements together, automatically separated into 2 lines  comma at the end of the first print statement suppress the line feed  comman for printing lists o
More Less

Related notes for CSC108H1

Log In


Join OneClass

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

Sign up

Join to view


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.