Weather Wise is a multiple choice weather quiz that users can play to help improve their knowledge about weather. It is a fun game for all ages, so everyone can play.
When a user first opens the quiz it will show a menu with a title and a brief overview of what the program actually is. Below this will be a list of options with what the user can do next. Depending on their choice it will either start the game, show the instructions on how to play or quit the game. If the user inputs an incorrect value they will then be informed that whatever they have just inputted was incorrect and they need to write either 1, 2 or 3 depending on what they would like to do. If the user inputs 2 into the program, it will then take them to the difficulty choosing section, where it will ask the user what level of difficulty the user would like for example easy, medium or hard. Again, if the user inputs an incorrect value it will tell them that they have done so and need to write either 1, 2 or 3. Following their choice it will then ask how many questions they would like to answer for example 10, 20 or 30. Once more if the user didn't type a correct value it will tell them so and that they need to type either 1, 2 or 3. After this the program will then access data from the questions library and start asking randomly chosen multiple choice questions up until the user has answered their desired amount. For example what is rain? a. God peeing b. condensation from clouds c. water squirting from plains d. water that falls from clouds in the sky. Once again, if the user doesn't input a, b, c or d for any question they will be told to write a correct value from the options given. When the quiz has been finished their score will be added up and then shown to the user. The user will then be asked to enter their name and that their score will then be added to the leaderboard and the top 10 scorers will then be shown in the leaderboard. The user will then be asked if they would like to play again or quit the game. If the user doesn't input a correct value again, they will be informed of this and asked to input a correct value. Providing they have chosen a correct value it will either take them to the difficulty choice section or show a message saying 'thank you for playing, goodbye'. However, at the menu screen if the user inputted the second option the app will then show the user how to play the quiz and once they have read this it will return them back to the menu. Finally, if the user chooses the last option it will then double check they want to quit and if they do it will show the thank you for playing, goodbye message.
Deployed site: https://ui.dev/amiresponsive?url=https://weather-wise-project-e6ccd7a6b753.herokuapp.com
source: amiresponsive
Header section
Menu section
Incorrect input for menu
Level option
Incorrect Level option
Amount option
Incorrect amount option
Rules option
Quit option
Incorrect quit option
The quiz
Incorrect value for quiz
Correct and incorrect values
Score
Finished
Incorrect value at finish
git add
, git commit
, git push
)To follow best practice, a flowchart was created for the app's logic, and mapped out before coding began using a free version of Draw.io.
Below is the flowchart of the main process of this Python program. It shows the entire cycle of the program.
I used Mermaid to create an interactive flowchart as well.
flowchart TD
Start([Start]) --> A1[Show menu of what the user needs to do and what the app does e.g. info of what program actually is 1. press 1 to show instructions 2. press 2 to play game 3. press 3 to quit.]
A1 --> B1[Asks user what difficulty level they want for example 1. easy 2. medium 3. hard]
B1 --> C1{1, 2 or 3}
C1 --> D1[Check what difficulty the user has inputted and then ask how many questions they want to answer e.g. 1. press 1 for 10 questions 2. press 2 for 20 questions 3. press 3 for 30 questions.]
D1 --> E1{1, 2 or 3}
E1 --> F1[Checks what amount the user would like then access data from the questions library and pulls random questions from this.]
F1 --> G1[Starts the quiz asking the user multiple choice questions e.g. what is a cloud? a. pillow b. the sky c. a group of tiny water droplets or ice crystals that float in the sky d. rain]
G1 --> H1{a, b, c or d}
H1 --> I1[When the user has answered their chosen amount of questions, they will then show their score and be asked to input their name.]
I1 --> J1[Their score will then be added to a leaderboard and they will then be asked if they'd like to play again or quit e.g. 1. press 1 to play again 2. press 2 to quit]
J1 --> K1{1 or 2}
K1 --> |1| A1
K1 --> |2| End([End])
A1 --> L1[Shows the user instructions on how to play the game.]
A1 --> M1[Shows a message making sure the user wants to quit the game e.g. 1. press 1 to keep playing 2. press 2 to quit.]
A1 --> N1[Incorrect input by user shows they inputted incorrect value and what they need to type.]
N1 --> A1
Source: Mermaid
The program uses classes as a blueprint for the project's objects (OOP). This allows for the object to be reusable.
class SelectionChecker:
""" Check user input and display errors if input is invalid. """
def __init__(self, selections):
self.selections = selections
class CheckerFactory:
""" Provides different types of selection checkers based on input. """
@staticmethod
class UIManager:
""" Handles the starting functions so the program can run. """
def __init__(self):
pass
class QuizGame:
""" Handles all the game functions. """
def __init__(self):
self.difficulty = None
self.num_questions = None
self.total_score = 0
class LeaderboardManager:
""" Authenticates to the Google Sheets API and returns the sheet object. """
def __init__(self):
self.sheet = None
class StyleHelper:
""" Handles all the styling operations and definitions. """
class ProgramHelper:
""" Handles all the helper functions. """
The primary functions used on this application are:
menu()
header()
check()
get_checker()
remove()
rules()
exit_game()
select_difficulty()
select_question_amount()
play()
get_user_answer()
show_score()
authenticate()
get_worksheet()
update_leaderboard()
show_leaderboard()
loading_message()
main()
I've used the following Python packages and/or external imported packages.
gspread
: used with the Google Sheets APIgoogle.oauth2.service_account
: used for the Google Sheets API credentialstime
: used for adding time delaysos
: used for adding a remove()
functioncolorama
: used for including color in the terminalrandom
: used to get a random choice from a listquestions
: used to pull all the questions from my own made filehelpers
: used to pull helper variables and functionsgame
: used for all the game functions the program useschecks
: used for error handlingstring
: used for adding ascii_lowercase
datetime
: used for adding the current time and datesys
: used to exit the programprettytable
: used to create the leaderboard table shown to the user[!NOTE]
For all testing, please refer to the TESTING.md file.
Code Institute has provided a template to display the terminal view of this backend application in a modern web browser. This is to improve the accessibility of the project to others.
The live deployed application can be found deployed on Heroku.
This project uses Heroku, a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud.
Deployment steps are as follows, after account setup:
PORT
, and the value to 8000
then select add.Python
first, then Node.js
second. (if they are not in this order, you can drag them to rearrange them)Heroku needs three additional files in order to deploy properly.
You can install this project's requirements (where applicable) using:
pip3 install -r requirements.txt
If you have your own packages that have been installed, then the requirements file needs updated using:
pip3 freeze --local > requirements.txt
The Procfile can be created with the following command:
echo web: node index.js > Procfile
The runtime.txt file needs to know which Python version you're using:
python3 --version
in the terminal.python-3.12.2
For Heroku deployment, follow these steps to connect your own GitHub repository to the newly created app:
Either:
Or:
heroku login -i
heroku git:remote -a app_name
(replace app_name with your app name)add
, commit
, and push
to GitHub, you can now type:
git push heroku main
The frontend terminal should now be connected and deployed to Heroku!
This application uses Google Sheets to handle a "makeshift" database on the live site.
To run your own version of this application, you will need to create your own Google Sheet with three sheets named easy
, medium
, and hard
in the following format:
Name | Score | Number of questions | Timestamp |
---|---|---|---|
Max | 3 | 10 | 2024-10-07 13:15:19 |
Molly | 14 | 20 | 2024-10-01 10:9:29 |
Melvin | 10 | 10 | 2024-10-07 16:5:9 |
A credentials file in .JSON
format from the Google Cloud Platform is also mandatory:
JSON
, and then click Create. This will trigger the .json
file with your API credentials in it to download to your machine locally.creds.json
.client_email
that is in the creds.json
file.client_email
, ensuring "Editing" is enabled.creds.json
file to your .gitignore
file, so as not to push your credentials to GitHub publicly.This project can be cloned or forked in order to make a local copy on your own system.
For either method, you will need to install any applicable packages found within the requirements.txt file.
pip3 install -r requirements.txt
.If using any confidential credentials, such as CREDS.json
or env.py
data, these will need to be manually added to your own newly created project as well.
You can clone the repository by following these steps:
git clone https://github.com/AshLaw96/weather-wise.git
Alternatively, if using Gitpod, you can click below to create your own workspace using this repository.
Please note that in order to directly open the project in Gitpod, you need to have the browser extension installed. A tutorial on how to do that can be found here.
By forking the GitHub Repository, we make a copy of the original repository on our GitHub account to view and/or make changes without affecting the original owner's repository. You can fork this repository by using the following steps:
No differences were found between the local version and the live deployed version of the program.
Source | Location | Notes |
---|---|---|
Markdown Builder | README and TESTING | tool to help generate the Markdown files |
YouTube | PP3 terminal | tutorial for adding color to the Python terminal |
Chatgpt | question.py | used to generate randomly made multiple choice questions |
geeksforgeeks | helpers.py | used for looking how to clear the terminal using the os library |
W3schools | helpers.py | used format() method to be able to center text |
geeksforkeeks | helper.py | used to understand how to use the sleep() method with the imported time library |
Python Docs | helpers.py | used to understand how to use the quit() method with the imported sys library |
W3Schools | helpers.py | used to understand how to use sample() method from the random library |
Python Docs | helper.py | used to understand how to use ascii_lowercase method from the string library |
Python Docs | helpers.py | used to understand how to use the walrus operator := |
Python Docs | helpers.py | used to understand how to use the timestamp method from the datetime library |
W3Schools | helpers.py | understand how to use now().strftime() method from the datetime library |
geeksforgeeks | checks.py | used to understand how to use @staticmethod in a class so that __init__ is not required |
W3Schools | run.py | used to understand how to use the pass keyword so that the program does not bring up a error |
Tim Nelson | entire site | used for ideas on how to structure the program |
W3Schools | game.py | used for understanding how to use the lambda function |
Stack Overflow | helpers.py | used to improve the remove function by using \033c escape code, so no left over lines show up |
Source | Location | Type | Notes |
---|---|---|---|
TinyPNG | entire site | image | tool for image compression |
GetEmoji | helpers.py | image | used to add emoji's to the program |
prettytable | game.py | leaderboard table | used to create the leaderboard image shown to the user |