forked from Pierian-Data/Complete-Python-3-Bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89020a5
commit 5886e8b
Showing
4 changed files
with
824 additions
and
0 deletions.
There are no files selected for viewing
154 changes: 154 additions & 0 deletions
154
02-Python Statements/.ipynb_checkpoints/09-Guessing Game Challenge-checkpoint.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Guessing Game Challenge\n", | ||
"\n", | ||
"Let's use `while` loops to create a guessing game.\n", | ||
"\n", | ||
"The Challenge:\n", | ||
"\n", | ||
"Write a program that picks a random integer from 1 to 100, and has players guess the number. The rules are:\n", | ||
"\n", | ||
"1. If a player's guess is less than 1 or greater than 100, say \"OUT OF BOUNDS\"\n", | ||
"2. On a player's first turn, if their guess is\n", | ||
" * within 10 of the number, return \"WARM!\"\n", | ||
" * further than 10 away from the number, return \"COLD!\"\n", | ||
"3. On all subsequent turns, if a guess is \n", | ||
" * closer to the number than the previous guess return \"WARMER!\"\n", | ||
" * farther from the number than the previous guess, return \"COLDER!\"\n", | ||
"4. When the player's guess equals the number, tell them they've guessed correctly *and* how many guesses it took!\n", | ||
"\n", | ||
"You can try this from scratch, or follow the steps outlined below. A separate Solution notebook has been provided. Good luck!\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"#### First, pick a random integer from 1 to 100 using the random module and assign it to a variable\n", | ||
"\n", | ||
"Note: `random.randint(a,b)` returns a random integer in range `[a, b]`, including both end points." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Next, print an introduction to the game and explain the rules" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Create a list to store guesses\n", | ||
"\n", | ||
"Hint: zero is a good placeholder value. It's useful because it evaluates to \"False\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Write a `while` loop that asks for a valid guess. Test it a few times to make sure it works." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"while True:\n", | ||
" \n", | ||
" pass" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Write a `while` loop that compares the player's guess to our number. If the player guesses correctly, break from the loop. Otherwise, tell the player if they're warmer or colder, and continue asking for guesses.\n", | ||
"\n", | ||
"Some hints:\n", | ||
"* it may help to sketch out all possible combinations on paper first!\n", | ||
"* you can use the `abs()` function to find the positive difference between two numbers\n", | ||
"* if you append all new guesses to the list, then the previous guess is given as `guesses[-2]`" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"while True:\n", | ||
"\n", | ||
" # we can copy the code from above to take an input\n", | ||
"\n", | ||
" pass" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"That's it! You've just programmed your first game!\n", | ||
"\n", | ||
"In the next section we'll learn how to turn some of these repetitive actions into *functions* that can be called whenever we need them." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Good Job!" | ||
] | ||
} | ||
], | ||
"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.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.