Presentation is loading. Please wait.

Presentation is loading. Please wait.

Course A201: Introduction to Programming 09/09/2010.

Similar presentations


Presentation on theme: "Course A201: Introduction to Programming 09/09/2010."— Presentation transcript:

1 Course A201: Introduction to Programming 09/09/2010

2 Recap [variable] – a name that carries/represents some value – You should give them values, before you use them because IDLE does not know what it is and what value it carries ex: service_rate = ‘good’ tip_percent = 0.15

3 Recap [types] integer – ex: 1; 3; 999; 8019 floating point (float) – ex: 0.8; 87.467; 3.14159 String – ex: “Hi”, “you name is: ”, “@$%^%$”

4 Recap [types] string: – consists of characters(letters, numbers, anything you can type in from keyboard) – always within single/double quotes – escape sequences: using back slash – ex: ‘good’; “Please enter: ”; ‘812000000’

5 Recap [types] string: – strings cannot be convert or compared to integers/floats unless they only contains numbers and are converted using type conversion functions – Ex: float(service) -> ERROR! Ex: ‘1’ == 1, result is False Ex: a = ‘1’; a + 2 -> ERROR!

6 Recap Type conversion functions: int(), str(), float() Variables/Values on both side of “+”(concatenation) should be in the same type Ex: num1 = 2, num2 = 3 “Sum of ” + num2 + “ and ” + num2 -> ERROR! “Sum of ” + str(num2) + “ and ” + str(num2) Be careful about logical errors

7 Recap [functions] I am a function. I will perform a certain job. input1, input2, input3, … output1, output2, output3, … You give me some inputs I give you some outputs back, explicitly or implicitly

8 Recap [functions: print] print: output things on the screen – Ex: date = ‘Sep. 23th’ print(‘Today is’, date) – All variables/values you put between parentheses are ARGUMENTS. (Important concept!!) Arguments are separated by comma ->, In the example above, you passes TWO arguments into the function print() Here

9 Recap [functions: print] print(“Sum of ” + num2 + “ and ” + num2) -> ERROR! print(“Sum of ”, num2, “ and ”, num2) -> CORRECT! – In the first line, the concatenation will be executed first, that’s when error happens. Variables/values on both sides of + should be in the same type – In the second line, there are 3 commas. So, you actually passed 4 arguments into function print. Different arguments can be in different types.

10 Recap [functions: raw_input] raw_input: reads anything the user input from keyboard, and returns the value (store it in a variable you named) as a STRING – Ex: service_rate = raw_input(‘Please enter the service rate: ’) After this, no matter what the user entered, service_rate would be a string. It is a prompt message

11 Recap [Arithmetic operations] – % : called modulo/modulus, returns remainder – / : division – // : floor division, returns the quotient – ** : exponent, 2**3 is 8 Due to version conflict, the safest way to perform any division, convert the integers to floating numbers first. a += 1 is short for a = a + 1

12 Have a nice weekend!


Download ppt "Course A201: Introduction to Programming 09/09/2010."

Similar presentations


Ads by Google