{ "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": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Explain what the cell below will produce and why. Can you change it so the answer is correct?" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "2/3" ] }, { "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": { "collapsed": true }, "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": [] }, { "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": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Strings" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Given the string 'hello' give an index command that returns 'e'. Use the code below:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "s = 'hello'\n", "# Print out 'e' using indexing\n", "\n", "# Code here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Reverse the string 'hello' using indexing:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "s ='hello'\n", "\n", "# Reverse the string using indexing\n", "\n", "# Code here" ] }, { "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": { "collapsed": true }, "outputs": [], "source": [ "s ='hello'\n", "\n", "# Print out the\n", "\n", "# Code here" ] }, { "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": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Reassign 'hello' in this nested list to say 'goodbye' item in this list:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": true }, "outputs": [], "source": [ "l = [1,2,[3,4,'hello']]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sort the list below:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": true }, "outputs": [], "source": [ "l = [5,3,4,6,1]" ] }, { "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": 10, "metadata": { "collapsed": true }, "outputs": [], "source": [ "d = {'simple_key':'hello'}\n", "# Grab 'hello'\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": true }, "outputs": [], "source": [ "d = {'k1':{'k2':'hello'}}\n", "# Grab 'hello'\n" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": true }, "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": { "collapsed": true }, "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": [] }, { "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": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "How do you create a tuple?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sets " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What is unique about a set?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use a set to find the unique values of the list below:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "l = [1,2,2,33,4,4,11,22,3,3,2]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Booleans" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For the following quiz questions, we will get a preview of comparison operators:\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
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.
<>If values of two operands are not equal, then condition becomes true. (a <> b) is true. This is similar to != operator.
>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.
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What will be the resulting Boolean of the following pieces of code (answer fist then check by typing it in!)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Answer before running cell\n", "2 > 3" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Answer before running cell\n", "3 <= 2" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Answer before running cell\n", "3 == 2.0" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Answer before running cell\n", "3.0 == 3" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Answer before running cell\n", "4**0.5 != 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Final Question: What is the boolean output of the cell block below?" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# two nested lists\n", "l_one = [1,2,[3,4]]\n", "l_two = [1,2,{'k1':4}]\n", "\n", "#True or False?\n", "l_one[2][0] >= l_two[2]['k1']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Great Job on your first assessment! " ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python [default]", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.3" } }, "nbformat": 4, "nbformat_minor": 0 }