Variables and Expressions
Craig Zilles (Computer Science) February 3, 2020 https://go.illinois.edu/cs105sp20
Variables and Expressions Craig Zilles (Computer Science) - - PowerPoint PPT Presentation
Variables and Expressions Craig Zilles (Computer Science) https://go.illinois.edu/cs105sp20 February 3, 2020 To Today 1. Objects, literals 2. Types and representation Integers Strings, Unicode, and Escaping Reals, floating point
Craig Zilles (Computer Science) February 3, 2020 https://go.illinois.edu/cs105sp20
2
functions and commands and how to write them
character in order to code?"
sequences was pretty difficult and confusing"
and should be gone over."
3
Use it to play around with the language
4
5
numbers
data
6
7
int 1 000110101 int 2 000101011 110101001
Type Number
Chunks (Store the number in binary)
Small number Large number
8 String 6 001000011 001010011
Type Number of characters Characters (Stored using Unicode encoding)
000100000 000110001 000110000 000110101 ‘CS 105’ C S 1 5
Whi Which o ch of t the he f followi wing ng ar are c cons nside dered ‘ d ‘whi whitespace pace’?
A) Spaces B) Tabs C) Newlines D) Spaces and Tabs E) Spaces, Tabs, and Newlines
9
Whi Which o ch of t the he f followi wing ng ar are c cons nside dered ‘ d ‘whi whitespace pace’?
A) Spaces B) Tabs C) Newlines D) Spaces and Tabs E) Spaces, Tabs, and Newlines
10
In computer programming, whitespace is any character or series of characters that represent horizontal or vertical space in typography. When rendered, a whitespace character does not correspond to a visible mark, but typically does occupy an area on a page. --Wikipedia
11 String 6 001000011 001010011
Type Number of characters Characters (Stored using Unicode encoding)
000100000 000110001 000110000 000110101 ‘CS 105’ C S 1 5
interpreted differently
12
A) 1 B) 2 C) 3 D) 4 E) 5
13
integers
each integer
numbers with a finite number of bits
14
15 Float
+22
Type Mantissa Exponent
Can specify in scientific notation
A) 1.000001 B) 1E-7 C) 1,097 D) -3.00 E) '\'\'\'' # Consists only of single quotes and slashes
16
type(expression)
and float()
17
18
19
statements
20
x = 2 y = x + 3 x = 5
A) 2 B) 3 C) 5 D) 8 E) 10
21
x = 7 y = x x = x + 2
A) 2 B) 5 C) 7 D) 9 E) None of the above
22
changed
doesn’t affect the others
23
interpreter gets rid of it.
24
https://cbtf.engr.illinois.edu/sched/
25
(our course administrator)
26
27
expression
28
() highest precedence
**
+x, -x
*, /, %
+, - lowest precedence Left-to-right within a precedence level
29
A) -9 B) -8 C) 8 D) 9 E) None of the above
31
number
32
total = num_machines * (cost_per_machine * (1 + tax_rate) + shipping rate)
machine_cost = num_machines * cost_per_machine machine_cost_with_tax = machine_cost * (1 + tax_rate) shipping_cost = num_machines * shipping_rate total = machine_cost_with_tax + shipping_cost
interpreter: x + y A) nothing B) SyntaxError C) NameError D) ValueError E) TypeError
33
expression:
34
value = input("Input your fave number!\n") print("Your new fave number is", value + 1)
A) No error B) SyntaxError C) NameError D) ValueError E) TypeError
35
remainder
y = (y // x) * x + (y % x).
36
dollars = product_cost_in_pennies // 100 cents = product_cost_in_pennies % 100
37
scratch
38
namespace
name: math.sin(7.3)
completion
39
reference
row and/or column
40
41
42