# ECS 32A Lecture 5: Arithmetic Expressions

57 views2 pages
17 Jan 2019
School
Course
Professor
1/16/2019
Arithmetic Expressions
Expression: code that evaluates to a value
Operators
Subtraction: -
Multiplication: *
Division: /
Exponent: **
Operator Precedence
Parentheses
Unary - (makes the value negative)
*,/,%
+,-
Within
any of these groups, the expression runs left to right
If you aren’t sure, always use parentheses
Special Rules for Arithmetic
Put spaces between operators and variables to increase readability
Do not put commas in numbers
1,000 is not correct
1000 is correct
Compound operators
x += 1
X = x + 1
x -= 3
X = x -3
x *= 3
X = x * 3
x /= 3
X = x/3
x %= 3
X % 3
Divisions and Modulo
/ operator automatically converts the quotient to a float
Integer division: // rounds down to the nearest integer
x //y: Number of times x goes evenly into y
Modulo is basically Remainder
Performs integer division
Throws the actual quotient away
Gives you the remainder: amount left over after the division
Writing and Importing Modules
Modules allow you to make your code modular
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

# Get access

\$10 USD/m
Billed \$120 USD annually
Homework Help
Class Notes
Textbook Notes