Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added content, minor fixes #8

Merged
merged 7 commits into from
Feb 20, 2018
Merged
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
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
}
Loading