{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

VariablesTypesMath-1

# VariablesTypesMath-1 - Variables Data Types Math Institute...

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

CS 1 with Robots Variables, Data Types & Math Institute for Personal Robots in Education (IPRE)

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

View Full Document
Aug 29 2007 2 Variables A variable is a name (identifier) that points to a value. They are useful to store values, and to refer to changing values by the same name. To create a variable, simply name it and assign it a value to point to with the assignment operator (single equal sign) >>> myName = “Jay” myName “Jay”
Aug 29 2007 3 Variables A variable name can be made up of letters, numbers, and the underscore ( _ ) character. The first character must be a letter. Variable names are case sensitive (myName and myname are different). >>> myname = “Scribbler” myName Jay myname Scribbler

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

View Full Document
Aug 29 2007 4 Variables >>> number1 = 3 >>> number2 = 2 >>> 3rdnumber = 5 Syntax Error: invalid syntax >>> import = 7 Syntax Error: invalid syntax number2 2 number1 3
Aug 29 2007 5 Using Variables When python sees a variable name, it evaluates the variable (sees what it points to) and uses the value that the variable points to instead of the variable name. >>> myName 'Jay' >>> number1 3 number1 3 myName “Jay”

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

View Full Document
Aug 29 2007 6 Using Variables If the python interpreter finds an identifier or variable name that has not yet been defined, it will return an error. >>> aRandomName NameError: name 'aRandomName' is not defined number1 3 myName “Jay”
Aug 29 2007 7 Using Variables You can do math with variables that point to numbers. The python interpreter evaluates the variables by checking to see what number (value) they are pointing to, and then uses that value for the math. >>> 3 + 2 5 >>> number1 + number2 5 number1 3 number2 2

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

View Full Document
Aug 29 2007 8 Using Variables You can even store the answer in a new variable.
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