{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

Booleans and Conditionals Lecture 5, Week 2 January 19, 2011 CSC108H1S Velian Pandeliev 1 Wednesday, January 19, 2011

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

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

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

View Full Document
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
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 float value long() a long value You can find out what a function does by using another built-in, help( functionname ) Wednesday, January 19, 2011

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

View Full Document
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
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

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

View Full Document
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
Input Example 9 Program: h = raw_input("Hours?: ") m = raw_input("Minutes?: ") print h * 60 + m Will this work?

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern