{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Objects and Data Structures Assessment Test"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Test your knowledge. \n",
"\n",
"** Answer the following questions **"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"Write a brief description of all the following Object Types and Data Structures we've learned about: "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Numbers:\n",
"\n",
"Strings:\n",
"\n",
"Lists:\n",
"\n",
"Tuples:\n",
"\n",
"Dictionaries:\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Numbers\n",
"\n",
"Write an equation that uses multiplication, division, an exponent, addition, and subtraction that is equal to 100.25.\n",
"\n",
"Hint: This is just to test your memory of the basic arithmetic commands, work backwards from 100.25"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Answer these 3 questions without typing code. Then type code to check your answer.\n",
"\n",
" What is the value of the expression 4 * (6 + 5)\n",
" \n",
" What is the value of the expression 4 * 6 + 5 \n",
" \n",
" What is the value of the expression 4 + 6 * 5 "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What is the *type* of the result of the expression 3 + 1.5 + 4?
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What would you use to find a number’s square root, as well as its square? "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Square root:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Square:\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Strings"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Given the string 'hello' give an index command that returns 'e'. Enter your code in the cell below:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s = 'hello'\n",
"# Print out 'e' using indexing\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Reverse the string 'hello' using slicing:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s ='hello'\n",
"# Reverse the string using slicing\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Given the string hello, give two methods of producing the letter 'o' using indexing."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s ='hello'\n",
"# Print out the 'o'\n",
"\n",
"# Method 1:\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Method 2:\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lists"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Build this list [0,0,0] two separate ways."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Method 1:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Method 2:\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Reassign 'hello' in this nested list to say 'goodbye' instead:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"list3 = [1,2,[3,4,'hello']]\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Sort the list below:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"list4 = [5,3,4,6,1]\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dictionaries"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using keys and indexing, grab the 'hello' from the following dictionaries:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d = {'simple_key':'hello'}\n",
"# Grab 'hello'\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d = {'k1':{'k2':'hello'}}\n",
"# Grab 'hello'\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Getting a little tricker\n",
"d = {'k1':[{'nest_key':['this is deep',['hello']]}]}\n",
"\n",
"#Grab hello\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# This will be hard and annoying!\n",
"d = {'k1':[1,2,{'k2':['this is tricky',{'tough':[1,2,['hello']]}]}]}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Can you sort a dictionary? Why or why not?
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Tuples"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What is the major difference between tuples and lists?
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"How do you create a tuple?
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Sets "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What is unique about a set?
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use a set to find the unique values of the list below:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"list5 = [1,2,2,33,4,4,11,22,3,3,2]\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Booleans"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For the following quiz questions, we will get a preview of comparison operators. In the table below, a=3 and b=4.\n",
"\n",
"
| Operator | Description | Example | \n", "
|---|---|---|
| == | \n", "If the values of two operands are equal, then the condition becomes true. | \n", "(a == b) is not true. | \n", "
| != | \n", "If values of two operands are not equal, then condition becomes true. | \n", "(a != b) is true. | \n", "
| > | \n", "If the value of left operand is greater than the value of right operand, then condition becomes true. | \n", "(a > b) is not true. | \n", "
| < | \n", "If the value of left operand is less than the value of right operand, then condition becomes true. | \n", "(a < b) is true. | \n", "
| >= | \n", "If the value of left operand is greater than or equal to the value of right operand, then condition becomes true. | \n", "(a >= b) is not true. | \n", "
| <= | \n", "If the value of left operand is less than or equal to the value of right operand, then condition becomes true. | \n", "(a <= b) is true. | \n", "