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
67 changes: 67 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Created by https://www.toptal.com/developers/gitignore/api/jupyternotebooks,macos,microsoftoffice
# Edit at https://www.toptal.com/developers/gitignore?templates=jupyternotebooks,macos,microsoftoffice

### JupyterNotebooks ###
# gitignore template for Jupyter Notebooks
# website: http://jupyter.org/

.ipynb_checkpoints
*/.ipynb_checkpoints/*

# IPython
profile_default/
ipython_config.py

# Remove previous ipynb_checkpoints
# git rm -r .ipynb_checkpoints/

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### MicrosoftOffice ###
*.tmp

# Word temporary
~$*.doc*

# Word Auto Backup File
Backup of *.doc*

# Excel temporary
~$*.xls*

# Excel Backup File
*.xlk

# PowerPoint temporary
~$*.ppt*

# Visio autosave temporary files
*.~vsd*

# End of https://www.toptal.com/developers/gitignore/api/jupyternotebooks,macos,microsoftoffice
46 changes: 46 additions & 0 deletions guess-the-number/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<img src="https://bit.ly/2VnXWr2" alt="Ironhack Logo" width="100"/>

# Guess the number
*_Alba Balcells_*

*_Data Analytics Barcelona, June 2020_*

## Content
- [Project Description](#project-description)
- [Rules](#rules)
- [Workflow](#workflow)
- [Organization](#organization)
- [Links](#links)

## Project Description
This code runs a "Guess the number" game, in which the user has to guess a number randomly generated by the computer.

## Rules

The user can choose between one of the default levels of difficulty (easy, medium, hard) or set up their own rules. Each level corresponds to a range of possible numbers and a maximum number of tries. The computer will pick a random number and the user will have to guess it. For every wrong guess, the code will display whether the guess is below or above the correct number. The game finishes when the user guesses the number or when they run out of tries.


## Workflow
- First, the code displays a welcome message with a brief introduction to the game.
- Then the user is asked to choose the level of difficulty (easy, medium, hard) or to set up their own rules ("let me choose" option).
- For each of the levels, the range of numbers and the maximum number of tries is set by default. For the "let me choose" option, the user is asked to input them instead.
- The computer randomly picks a number within the range specified.
- The user inputs their guess, and the code tells them whether they are correct or not. If they are not, the code informs whether their guess is above or below the correct number.
- The game will go on until the user inputs the correct guess or the maximum number of tries is reached.
- When one round is over, the user will choose whether to keep playing or to exit the game.

__Note__: a warning message will be displayed when the user's input is not expected (e.g. text instead of number)


## Organization
Used Trello to keep track of all the taskes.

Inside the repository there is a folder named _Guess the number_. The folder contains two Jupyter Notebook files, one with only the code and another with detailed explanations.

## Links
Include links to your repository, slides and kanban board. Feel free to include any other links associated with your project.

[Repository](https://github.com/albabalcells/Project-Week-1-Build-Your-Own-Game/)
[Slides](https://drive.google.com/file/d/1n6W0RmnpQ2h1Cz5_a1qgrkOJJwbQbCGX/view?usp=sharing)
[Trello](https://trello.com/b/QHmS0QUS/project-1-build-your-own-game/)

71 changes: 71 additions & 0 deletions guess-the-number/Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"import random"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"correct=random.sample(range(10),1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Choose a number between 1 and 10: 1\n",
"Choose a number between 1 and 10: 2\n",
"Choose a number between 1 and 10: 3\n",
"Choose a number between 1 and 10: 4\n",
"Choose a number between 1 and 10: 5\n",
"Choose a number between 1 and 10: 6\n",
"Choose a number between 1 and 10: 7\n",
"Choose a number between 1 and 10: 8\n",
"Choose a number between 1 and 10: 9\n",
"Choose a number between 1 and 10: 10\n"
]
}
],
"source": [
"number=int(input(\"Choose a number between 1 and 10: \"))\n",
"while number!=correct:\n",
" number==int(input(\"Choose a number between 1 and 10: \"))\n",
" if number==correct:\n",
" print(\"You win!\")\n",
"if number==correct:\n",
" print(\"You win!\")\n",
"number"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
196 changes: 196 additions & 0 deletions guess-the-number/code-explained.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Guess the number!\n",
"\n",
"This is a _Guess the number_ game. To play, you will have to choose between 3 levels of difficulty, or choose the rules yourself! The computer will generate a random number and you will have to guess it. \n",
"The code will tell you whether your guess is below or above the correct number, but be careful, you only have a limited number of tries!\n",
"\n",
"__Good luck!__"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Def ask_new_round() and set it to \"yes\" for first round:\n",
"def ask_new_round():\n",
" choice=input(\"Do you want to play another round? \").lower()\n",
" while choice not in [\"yes\", \"no\"]:\n",
" choice=input(\"Please, say yes or no: \").lower()\n",
" return choice\n",
"new_round=\"yes\"\n",
"\n",
"#Start game\n",
"while new_round==\"yes\":\n",
" \n",
" #Ask for the level they want to play\n",
" levels=[\"easy\", \"medium\", \"hard\", \"let me choose\"]\n",
" def ask_level():\n",
" choice=input(\"\\nPick your level: easy, medium or hard? If you want to choose the rules yourself, please type 'let me choose' \").lower()\n",
" while choice not in levels:\n",
" print(\"\\nPlease, choose one of the options\")\n",
" choice=input(\"\\nPick your level: easy, medium or hard? If you want to choose the rules yourself, please type 'let me choose' \").lower()\n",
" return choice\n",
" level=ask_level()\n",
"\n",
" #Set range of numbers and number of tries according to the level chosen\n",
" if level==\"easy\":\n",
" numbers=list(range(1,11))\n",
" tries=4\n",
" print(\"Great! You'll have to pick a number between 1 and 10. You have 4 turns to get it right. Let's play!\\n\")\n",
" elif level==\"medium\":\n",
" numbers=list(range(1,101))\n",
" tries=7\n",
" print(\"Great! You'll have to pick a number between 1 and 100. You have 7 turns to get it right. Let's play!\\n\")\n",
" elif level==\"hard\":\n",
" numbers=list(range(1,1001))\n",
" tries=10\n",
" print(\"Great! You'll have to pick a number between 1 and 1000. You have 10 turns to get it right. Let's play!\\n\")\n",
" else:\n",
" #Define variables for \"let me choose\" option\n",
" print(\"\\nGreat! You'll have to choose the minimum and maximum numbers you want the game to have, and how many turns do you want to have to guess it. Let's play!\\n\")\n",
" \n",
" range_num=range(-100000,100001)\n",
" range_str=[]\n",
" for i in range_num:\n",
" range_str.append(str(i))\n",
"\n",
" range_tries_good=list(range(1,21))\n",
" range_tries_good_str=[]\n",
" for i in range_tries_good:\n",
" range_tries_good_str.append(str(i))\n",
"\n",
" range_tries_bad=list(range(21,101))\n",
" range_tries_bad_str=[]\n",
" for i in range_tries_bad:\n",
" range_tries_bad_str.append(str(i))\n",
" \n",
" total_tries_range=range_tries_good_str+range_tries_bad_str\n",
" \n",
" #Ask for minimum number in the range, function will only take numbers\n",
" def custom_range_min():\n",
" choice=input(\"\\nChoose the minimum value of your range: \")\n",
" while choice not in range_str:\n",
" choice=input(\"Please, choose a number: \")\n",
" return int(choice)\n",
"\n",
" #Ask for minimum number in the range, function will only take numbers higher than the minimum set up before\n",
" def custom_range_max():\n",
" choice=input(\"\\nChoose the maximum value of your range: \")\n",
" while choice not in range_str:\n",
" choice=input(\"Please, choose a number higher than {}: \".format(range_min))\n",
" while choice in range_str and int(choice)<=range_min:\n",
" if choice in range_str:\n",
" choice=input(\"Please, choose a number higher than {}: \".format(range_min))\n",
" while choice not in range_str:\n",
" choice=input(\"Please, choose a number higher than {}: \".format(range_min))\n",
" else:\n",
" return int(choice)\n",
"\n",
" #Ask for number of tries. Maximum available is 100. If tries>20, the code will display a warning message. \n",
" def custom_tries():\n",
" choice=input(\"\\nNow choose how many tries you want to have: \")\n",
" while choice not in total_tries_range:\n",
" choice=input(\"\\nPlease, choose a number between 1 and 100: \")\n",
" if choice in range_tries_bad_str:\n",
" answer=input(\"Wow, this a very high number of tries, are you sure you want to proceed? \").lower()\n",
" if answer==\"yes\":\n",
" return int(choice)\n",
" elif answer==\"no\":\n",
" choice=input(\"\\nOkay then, choose again a number between 1 and 100: \")\n",
" return int(choice)\n",
" while answer not in [\"yes\", \"no\"]:\n",
" answer=input(\"Please, say yes or no \")\n",
" if choice in range_tries_good_str:\n",
" return int(choice)\n",
" if choice in range_tries_bad_str:\n",
" answer=input(\"Wow, this a very high number of tries, are you sure you want to proceed? \").lower()\n",
" if answer==\"yes\":\n",
" return int(choice)\n",
" elif answer==\"no\":\n",
" choice=input(\"\\nPlease, choose a number between 1 and 100: \")\n",
" return int(choice)\n",
" while answer not in [\"yes\", \"no\"]:\n",
" answer=input(\"Please, say yes or no \")\n",
" elif choice in range_tries_good_str:\n",
" return int(choice)\n",
"\n",
" #Assign inputs from user to variables numbers and tries\n",
" custom_range_min\n",
" range_min=custom_range_min()\n",
" range_max=custom_range_max()\n",
" numbers=list(range(range_min,range_max+1))\n",
" tries=custom_tries()\n",
" \n",
" #Generate random correct number\n",
" import random\n",
" correct_number=random.choice(numbers)\n",
" \n",
" #Define function for user's guessed number\n",
"\n",
" #Making a list of the number range chosen, each number stored as a string so that then it works when using input(), as the answer from the user will be stored as a string. We need this to make sure the input they put is in the range of numbers chosen.\n",
" str_numbers=[]\n",
" for i in numbers:\n",
" str_numbers.append(str(i))\n",
" \n",
" #Ask user for number and then turn it into a integer to compare it with the correct value\n",
" def ask_number():\n",
" choice1=input(\"Pick a number between {} and {}: \".format(str(min(numbers)), str(max(numbers))))\n",
" while choice1 not in str_numbers:\n",
" choice1=input(\"Please, pick a number between {} and {}: \".format(str(min(numbers)), str(max(numbers))))\n",
" return int(choice1)\n",
"\n",
" #Run game\n",
" tries_count=0\n",
" for i in range(0, tries):\n",
" guess_number=ask_number()\n",
" if guess_number==correct_number:\n",
" print(\"Congratulations! You guessed the number!\\n\")\n",
" break\n",
" elif guess_number<correct_number and tries_count<tries-1:\n",
" tries_count+=1\n",
" print(\"You are too low, try again! Tries left:\", tries-tries_count, \"\\n\")\n",
" continue\n",
" elif guess_number>correct_number and tries_count<tries-1:\n",
" tries_count+=1\n",
" print(\"You are too high, try again! Tries left:\", tries-tries_count, \"\\n\")\n",
" continue\n",
" else:\n",
" print(\"You don't have any tries left, you lose the game. The correct number was\", correct_number, \"\\n\")\n",
" \n",
" #Ask if the want to play another round\n",
" new_round=ask_new_round()\n",
"\n",
"else:\n",
" print(\"Okay, thanks for playing the game. See you next time!\")"
]
}
],
"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.8.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading