# Numbers

Hint: This is just to test your memory of the basic arithmetic commands, work backward from 100.25

In :

`x = 1.25 + (5**2*8/2) - 1print(x)100.25Answer these 3 questions without typing code. Then type code to check your answer.What is the value of the expression 4 * (6 + 5) - 44What is the value of the expression 4 * 6 + 5 - 29What is the value of the expression 4 + 6 * 5 - 34`

In :

`x = 4 * (6 + 5)y = 4 * 6 + 5z = 4 + 6 * 5print(x,y,z)44 29 34What is the *type* of the result of the expression 3 + 1.5 + 4?<br><br> - float`

What would you use to find a number’s square root, as well as its square?

In :

`# Square root:16**(0.5)`

Out:

`4.0`

In :

`# Square:4**2`

Out:

`16`

# Strings

In :

`s = 'hello'# Print out 'e' using indexings`

Out:

`'e'`

Reverse the string ‘hello’ using slicing:

In :

`s ='hello'# Reverse the string using slicings[::-1]`

Out:

`'olleh'`

Given the string hello, give two methods of producing the letter ‘o’ using indexing.

In :

`s ='hello'# Print out the 'o'# Method 1:print(s[-1])`

In :

`# Method 2:print(s)`

# Lists

In :

`# Method 1:mylist = [0,0,0]`

In [ ]:

`# Method 2:`

Reassign ‘hello’ in this nested list to say ‘goodbye’ instead:

In :

`list3 = [1,2,[3,4,'hello']]list3.pop(2)print(list3)list3.append('goodbye')print(list3)[1, 2, [3, 4]][1, 2, [3, 4, 'goodbye']]`

Sort the list below:

In :

`list4 = [5,3,4,6,1]list4.sort()print(list4)[1, 3, 4, 5, 6]`

# Dictionaries

In :

`d = {'simple_key':'hello'}# Grab 'hello'd['simple_key']`

Out:

`'hello'`

In :

`d = {'k1':{'k2':'hello'}}# Grab 'hello'd['k1']['k2']`

Out:

`'hello'`

In :

`# Getting a little trickerd = {'k1':[{'nest_key':['this is deep',['hello']]}]}#Grab hellod['k1']['nest_key']`

Out:

`['hello']`

In :

`# This will be hard and annoying!d = {'k1':[1,2,{'k2':['this is tricky',{'tough':[1,2,['hello']]}]}]}d['k1']['k2']['tough']`

Out:

`['hello']Can you sort a dictionary? Why or why not?<br><br> Dictionaries are mappings not sequences. so cant be orderded`

# Tuples

`What is the major difference between tuples and lists?<br><br> tuples immutable. How do you create a tuple?<br><br> parantheses cruve brackets`

# Sets

`What is unique about a set?<br><br> only one item of each`

Use a set to find the unique values of the list below:

In :

`list5 = [1,2,2,33,4,4,11,22,3,3,2]x = set(list5)print(x){1, 2, 33, 4, 3, 11, 22}`

# Booleans

OperatorDescriptionExample==If the values of two operands are equal, then the condition becomes true.(a == b) is not true.!=If values of two operands are not equal, then condition becomes true.(a != b) is true.>If the value of left operand is greater than the value of right operand, then condition becomes true.(a > b) is not true.<If the value of left operand is less than the value of right operand, then condition becomes true.(a < b) is true.>=If the value of left operand is greater than or equal to the value of right operand, then condition becomes true.(a >= b) is not true.<=If the value of left operand is less than or equal to the value of right operand, then condition becomes true.(a <= b) is true.

What will be the resulting Boolean of the following pieces of code (answer first then check by typing it in!)

In :

`# Answer before running cell : false2 > 3`

Out:

`False`

In :

`# Answer before running cell:false3 <= 2`

Out:

`False`

In :

`# Answer before running cell:false3 == 2.0`

Out:

`False`

In :

`# Answer before running cell:true3.0 == 3`

Out:

`True`

In :

`# Answer before running cell:false4**0.5 != 2`

Out:

`False`

Final Question: What is the boolean output of the cell block below?

In :

`# two nested listsl_one = [1,2,[3,4]]l_two = [1,2,{'k1':4}]# True or False? falsel_one >= l_two['k1']`

Out:

`False`