108HL05 - Booleans and Conditionals Lecture 5, Week 2...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Booleans and Conditionals Lecture 5, Week 2 January 19, 2011 CSC108H1S Velian Pandeliev 1 Wednesday, January 19, 2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Announcements Labs start today! There has been a change to lab rooms refected in the Lab Room announcement: BA3185 has been replaced with BA3175. No Quiz Today! Wednesday, January 19, 2011
Background image of page 2
3 Built-Ins and User Input Wednesday, January 19, 2011
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Built-in Functions 4 Python comes with some built-in functions that make programming easier. Some are math functions: function computes parameters abs() absolute value 1 max() maximum of several #s 2+ min() minimum of several #s 2+ pow() same as ** 2 Wednesday, January 19, 2011
Background image of page 4
Data Type Conversion 5 Some built-in functions allow you to convert between data types: function converts to str() a str value int() an int value float() a Foat value long() a long value You can ±nd out what a function does by using another built-in, help( functionname ) Wednesday, January 19, 2011
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Getting Data From the User 6 There's a built-in function that allows a Python program to ask for data from the user before continuing: raw_input( prompt_string ) - Displays prompt_string to the user instructing her to enter a value. - The user types in the value and presses Enter. - The result of a raw_input() call is a string which can be assigned to a variable. Wednesday, January 19, 2011
Background image of page 6
Getting Data From the User 7 >>> x = raw_input("Raw input: ") Raw input: 66 >>> x '66' >>> x = raw_input("Raw input: ") Raw input: Hello >>> x 'Hello' Wednesday, January 19, 2011
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Input Example 8 Example: We would like to ask the user for a number of hours and a number of minutes, and print out the total number of minutes. Algorithm: - we ask for hours and store as a variable ( h ) - we ask for minutes and store as a variable ( m ) - we compute h * 60 + m - we print the result Wednesday, January 19, 2011
Background image of page 8
Input Example 9 Program: h = raw_input("Hours?: ") m = raw_input("Minutes?: ") print h * 60 + m Will this work?
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/25/2011 for the course CSC 108 taught by Professor Gries during the Spring '08 term at University of Toronto- Toronto.

Page1 / 31

108HL05 - Booleans and Conditionals Lecture 5, Week 2...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online