Use code to determine the answers to the question 1.1-1.4
What is the type of 1
? Use the function type
to determine.
int
What about the type of 1.0
?
What is the resulting type of adding an 1
and 1
?
What is different about the resulting type of adding 1
and 1.0
?
So, what can you say about the resulting type of adding an int
and a float
?
Use code to determine the answers to the question 2.1-2.4
What is the type of "Jelani"
?
What is the type of 'Computer'
?
What happens when you add "Jelani"
and 'Computer'
?
What is the resulting type of adding "Jelani"
and 'Computer'
?
Is there a difference between single quotes and double quotes?
What happens when you add two strings (with the +
operator)?
Use code to determine the answers to the question 3.1
What is the resulting type of adding 3
and '3'
?
Can you explain why the error occured?
Use code to determine the answers to the question 4.1-4.4
Make a list that contains 4
and 5.0
.
Can you make a list that has 1
, 2
and "Jelani"
in it?
Can you make a list that contains 1
, 2
, "Jelani"
, and [4, 5.0]
?
Think about another type we haven't used in Question 4. Can you put it in the list of [1, 2.0]
?
What types can lists contain?
Add lists [5, 6, 'pom']
and [True, 12, 5.0]
together. What happens?
Use code to determine the answers to the question 5.1-5.4
Multiply 5
and 4
.
Multiply 'Shiro'
by 3
.
Multiply 5.0
and 4
.
Multiply ['Shiro', 5]
by 4
.
What patterns emerge when you multiply different types with an integer?
The upper left corner that's colored represents the operator. For example, in figure 1, B represents the result of False and True.
What are the boolean values of A through H? Use your intuition.
Fill out this list.
A.
B.
C.
D.
E.
F.
G.
H.
Use code to check your above answers.
# Explore here
Are 3
and '3'
equivalent? Use code to confirm.
Are "Jelani"
and "jelani"
equivalent? Use code to confirm.
What is the result of (not False) == True
?
Define a variable x
, that has a value of 5
.
Define a variable y
, that has a value of x
.
What is the value of y
?
Change x
to 4
. What is the value of y
?
Define a variable z
, that has a value of the sum of x
and y
Assign x
another value, 12
. What are the values of y
and z
?
Define a variable x
and assign it the value of False
, but without using the keyword False
.
Hint: You can do it using one special operator.
Given the following lines of code, what is the value of the variable seven
?
seven = 8
seven = 8
seven
Given the following lines of code, are the variables shiro
and Shiro
equivalent?
shiro = 10
Shiro = 12
shiro == Shiro
Define a variable x
that has the value 10
times 20
.
Now increment x
by 3.
Can you increment x
by 3 in a different way (using a different operator)?
Find the remainder of 78
divided by 14
using one operator from lecture. For example -
$16 = 5 * 3 + 1$ (1 is the remainder).
Given x
, make x
10 times smaller using one operation. Return a value that has the type int
.
What type(s) can you multiply lists with, without creating an error?
Write code to produce
a. 'ShiroShiroShiro'
b. 'Shiro3'
You should only type 'Shiro'
once and 3
once for each case.
Look at the following code
x = 99
x /= 10
x *= 50
y = x
y += 5
x -= y
y %= x
What is x
and y
? Try to do it in your head (or on paper) first before trying it with code.