Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

823 changes: 823 additions & 0 deletions week2/.ipynb_checkpoints/Keep tryin-checkpoint.ipynb

Large diffs are not rendered by default.

1,049 changes: 1,049 additions & 0 deletions week2/.ipynb_checkpoints/Lab1-checkpoint.ipynb

Large diffs are not rendered by default.

285 changes: 285 additions & 0 deletions week2/.ipynb_checkpoints/PSET_1_Intro to Python-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem Set 1: Intro to Python\n",
"This problem set is meant to create a good foundation of programming. We emphasize code readability and reusability over performance. Code performance can be measured in many different ways, and is by no means the focus of this course, however, we expect your code to be non-repetitive, clean, and efficient enough to deal with medium-to-large datasets. As we move forward with the course, you will be introduced to some functional programming techniques, iterators, and objects that will help speed-up the data munging of the type of data sets that we will be dealing with. \n",
"\n",
"`Throughout the course you will be using multiple online resources to help you solve the assignments, we do too. However, if you are using other people’s code, make sure to credit the source, and come up with your own implementation. In this problem set, you are welcome to refer to online resources and documentation. One of the primary ones you will find you use is:` [Stack Overflow]( http://stackoverflow.com/)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Lists\n",
"Do the following:\n",
"1. Create a list containing any 4 strings.\n",
"2. Print the 3rd item in the list\n",
"3. Print the 1st and 2nd item in the list using [:] index slicing.\n",
"4. Add a new string with text “last” to the end of the list and print the list.\n",
"5. Get the list length and print it.\n",
"6. Replace the last item in the list with the string “new” and print\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Strings \n",
"Given the following list of words:\n",
"```Python\n",
"list1=['I', 'am', 'learning','Python','to','munge','large','datasets','and','visualize','them']\n",
"```\n",
"1. Convert the list into a normal sentence with [`join()`](https://docs.python.org/2/library/stdtypes.html#str.join), then print.\n",
"2. [**Reverse**](https://docs.python.org/release/2.3.5/whatsnew/section-slices.html) the order of this list `[“them”,”visualize”,…]`\n",
"3. Now [**sort**](https://docs.python.org/2/library/functions.html#sorted) the list using the default sort order in python\n",
"4. Modify the sort to do a case [**insensitive**](http://matthiaseisen.com/pp/patterns/p0005/) alphabetic sort\n",
"5. Now print the list in reverse alphabetic sort order\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Random Function\n",
"Here is a python snippet for generating a random integer:\n",
"\n",
"```Python\n",
"import random\n",
"# this returns random integer: 100 <= number <= 1000 \n",
"num = random.randint(100, 1000)\n",
"```\n",
"\n",
"* Implement your own random function that builds on this python function, returning an integer between a low and a high number supplied by the user, but that can be called with the low number optional (default to 0).\n",
"\n",
"* Test your function by adding the following 2 assert statements to your file (replace myrandom and low with the names you used). The [`assert`](https://docs.python.org/2/reference/simple_stmts.html#assert) statement helps you debug, by testing if a statement is true. \n",
"\n",
"```Python\n",
"assert(0 <= myrandom(100) <= 100)\n",
"assert(50 <= myrandom(100,low=50) <= 100)\n",
"```\n",
"\n",
"\n",
"1. Inputs: \n",
" 1. Two `integers` that will be used as lower and upper bounds of the function. \n",
"2. Outputs: \n",
" 1. A random number within the established bounds. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. String Formatting Function \n",
"Write a function that expects 2 inputs from the command line. The first is a title that may be multiple words, the second is a number. Given these inputs print the following string (replacing N and Title with the dynamic values passed in to the script each time it runs).\n",
"\n",
"`The number N bestseller today is: Title` \n",
"\n",
"* If not already title-cased, the function should **title-case** the string. \n",
"* Build one function making the first input optional (keeping the 2nd required).\n",
"* Build another function making the second input optional (keeping the 1st required).\n",
"* Build a third function making both inputs optional.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Password Validation Function \n",
"Write a password validation function. Ask the user to input a password that meets the criteria listed below. You can either use the **Python** [`input`](https://docs.python.org/3/library/functions.html#input) built-in function, or just pass the password as a function argument. Validate that the user’s password matches this criteria. After 3 bad tries, quit with an error message. If password is valid, print a helpful success message.\n",
"\n",
"* password length must be 8-14 characters\n",
"* password must contain at least 2 digits\n",
"* password must contain at least 1 uppercase letter\n",
"* password must contain at least 1 special character from this set !@#$%^&*()-_+=\n",
"\n",
"\n",
"\n",
"1. Inputs: \n",
" 1. A `string` that will be tested for the password requirements. The string can be passed as an argument to the function, or as an input through the `input` function.\n",
"2. Outputs: \n",
" 1. A **success** message if the password works, otherwise an **error** message. \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Exponentiation Function\n",
"Create a function called **exp** that asks for two digits and then prints an exponentiation, without using the exponentiation operator (`**`). You may assume these are positive integers. Use at least one custom-defined function.\n",
"\n",
"For example, some outputs of this function could be:\n",
"* 2 , 3 => 8\n",
"* 5 , 4 => 625\n",
"\n",
"1. Inputs: \n",
" 1. An `integer` that will be recursively multiplied\n",
" 2. An `integer` that will define the number of times to multiply the number to get the exponentiation.\n",
"2. Outputs: \n",
" 1. An `integer` that is the result of the exponentiation. \n",
"\n",
"`Hint: You can recursively multiply a number. The second number defines the number of times the recursive loop happens. Every time the loop happens, you can redefine the variable that gets multiplied.` "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 7. Min and Max Functions (Bonus)\n",
"\n",
"EXTRA CREDIT\n",
"\n",
"Write your own versions of the Python built-in functions **min** and **max**. They should take a list as an argument and return the minimum or maximum element. Assume lists contain numeric items only. \n",
"\n",
"1. Inputs: \n",
" 1. A `list` of `numbers` to be tested. \n",
"2. Outputs: \n",
" 1. A `number` of the list that is the maximum or minimum. \n",
"\n",
"`Hint: Pick the first element as the minimum(maximum) and then loop through the elements to find a smaller(larger) element. Each time you find a smaller (larger) element, update your minimum (maximum).`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 8. Hangman Game (Bonus)\n",
"\n",
"EXTRA CREDIT\n",
"\n",
"Implement a basic hangman game through functions.\n",
"* Show a user the word or phrase (5-15 letters) that they have to guess with dashes as placeholders for unsolved letters. You can hardcode this word into your source.\n",
"* Prompt the user to guess a letter or solve the puzzle through the user [`input`](https://docs.python.org/2/library/functions.html#input) function. They get up to 8 guesses. After each guess, show the word with any instances of correctly guessed letters filled in. Show the number of tries left. Handle possible issues with user input in a consistent way.\n",
"* Continue to prompt the user until either they’ve used up their 8 guesses or solved.\n",
"* If they solve the puzzle in time, show the completed word and a congratulatory message.\n",
"* If they fail to solve the puzzle, show the completed word and a Game Over message.\n",
"\n",
"\n",
"Here’s a sample transcript.\n",
"> You have 8 guesses to solve this word. \n",
"\n",
">------------------------------------------ \n",
"\n",
">guess a letter or solve: b \n",
"\n",
">b--b--b-- (7 tries left) \n",
"\n",
">guess a letter or solve: x \n",
"\n",
">b--b--b-- (6 tries left) \n",
"\n",
">guess a letter or solve: e \n",
"\n",
">b--b-ebee (5 tries left) \n",
"\n",
">guess a letter or solve: bumblebee \n",
"\n",
">bumblebee (4 tries left) \n",
"\n",
">Congratulations, you won!\n",
"\n",
"1. Inputs: \n",
" 1. A `string` that will be tested to see whether or not it is part of the secret word. \n",
"2. Outputs: \n",
" 1. A message that shows the user the number of guessed letters at the time.\n",
" 2. A **success** message if the user wins, otherwise a **try again** message. \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading