Class Notes (835,760)
Canada (509,376)
CMPT 165 (21)
Lecture

# CMPT165-Variables.docx

5 Pages
120 Views

School
Department
Computing Science
Course
CMPT 165
Professor
Colin Stewart
Semester
Winter

Description
Variables Strings Floats Integers printAdding ProgramxrawinputEnter the 1st number to add yrawinputEnter the 2nd number to add sumxy print Sumsum And the corresponding program output user input in boldAdding ProgramEnter the 1st number to add2 Enter the 2nd number to add3 Sum23 Our program is telling us that 2323 When we added the variables x and y together with theoperator they were not added mathematically but rather joined together The reason this happens is because what we get from the user via rawinput is stored as a string and not as a number A string is a sequence of characters Characters are anything that you can type on a keyboard Letters Digits Spaces Punctuation When you add two strings together with theoperator the strings are attached together So if we type two words into our calculator eg pot and ash then the result will be the two words joined together eg potashAdding ProgramEnter the 1st number to addpot Enter the 2nd number to addash Sumpotash If we want Python to treat x and y as numbers we will have to tell it to do this To treat x and y as numbers we will have to convert them from strings to numbers That is we have to change their data type All variables have a specific data type The data type of a variable lets Python know how to treat the variable Eg Adding two strings together will attach them together whereas adding two numbers together will mathematically add them String str Stores a sequence of characters Integer int Stores a whole number no decimal point Floating point float Stores a number with a decimal point
More Less

Related notes for CMPT 165
Me

Log In

OR

Join OneClass

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

Sign up

Join to view

OR

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.

Request Course
Submit