{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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
Image of page 1

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

View Full Document Right Arrow Icon
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
Image of page 2
3 Built-Ins and User Input Wednesday, January 19, 2011
Image of page 3

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

View Full Document Right 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
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 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
Image of page 5

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

View Full Document Right 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
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
Image of page 7

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

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

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern