/CI_PP_3

Primary LanguagePython

Canadian Slang Quiz

Website responsive

Canadian Slang Quiz is Python terminal quiz game, which runs in the Code Institute mock terminal on Heroku.
Users can test their knowledge of Canadian slang through this quiz. For each term, there are three possible answers from which the user chooses one. For the correct answer, an example of the use of the term is also provided.

Here you have a live version of the project.


Table of Contents

  1. Flowchart

  2. UX
  1. How to Play
  1. Features
  1. Validation and Testing
  1. Deployment
  1. Credits

  2. Tools and Platforms

  3. Content

  4. Media


Flowchart

The flowchart that was the guideline during the coding process, there were some deviations, but in principle it served as a guide.
Flowchart


UX

Visitor Goals

The target audience for Canadian Slang Quiz are:

  • People who are interested in languages (in this case English spoken in Canada).
  • People who already know Canadian slang, but want to confirm their knowledge
  • People who want to learn some Canadian slang.
  • People who immigrated to Canada and want to integrate by learning local slang.
  • People who want to have fun and learn something new.

User goals are:

  • To learn new words through a quiz, and by scoring to motivate to score as many points as possible.
  • To have fun while learning by competing against opponents.
  • To get to know Canada itself through new learned words, for which they will get an explanation.
  • To challenge yourself and question your existing knowledge.

Business Goals

The Business Goals of Canadian Slang Quiz are:

  • To provide a simple educational quiz.
  • Where through the use of the application, users gain knowledge of Canadian slang.
  • By scoring the results, users are encouraged to repeat the quiz in order to be more successful and thus learn faster.
  • Get users interested in Canadian culture.

User Stories

  • As a user interested in the quiz, I expect the game instructions to be clear and not complicated.
  • That my score is displayed in the table, and that I can compete with my friends who will get more points.
  • As a user who is interested in language quizzes, I want to get an explanation for the given term (question).

How to Play

How to Play
Canadian Slang Quiz is a classic quiz game, with a set question, in this case the question is a language term and three possible answers, one of which is correct.

  • Upon launching the application, a welcome message and game rules are displayed.
  • For each question there are three offered answers, to which the user answers by entering one of three options: A, B or C.
  • The user is given the option to continue with the game and type in name or to quit.
  • After ten questions, the user receives as a result the percentage of correctly answered questions entered in the results table.
  • The user also receives a congratulatory message and a question whether he wants to repeat the game or to quit.

Features

  • The first thing I wanted users to encounter were:
    • The welcome message with something typical of Canada, in this case a Maple Leaf ASCII Art
    • The rules of the game, to familiarize them with what awaits them
    • And to give them the opportunity to decide whether they want to continue or quit. In order to keep repeating the question until an affirmative or negative answer is obtained, in order to achieve this I decided to use a "while loop" and a "break statement", and to quit the game I used the built-in Python quit() Function (After researching, solution discovered on exit() in Python).
    • To control the flow of response input, I opted for "if / else Statements" where I decided to convert the user's response to lowercase using the string lower() Method for comparison How to Play
  • Then I wanted the user to be greeted after entering the name and after completing the quiz, his personal score would be entered in the table.
  • For the name query, I opted for the Built-in Function input() as a simple and effective solution, and I decided not to limit the input of the name to letters only, because there might be multiple users of the same name. So, users can use other characters to distinguish themselves.
  • Since I wanted to use the username and result for messages through other functions, I added the Keyword global even though it may lead to potential problems when extending the application. But given the current scope of the game, I found it acceptable (although I plan on removing them in future versions). While the other variables to which I first assigned global(example: global meaning), I removed and added as an argument to the functions that use them(check_answer(user_answer, correct_answer, meaning)). Username and question
  • As for the quiz itself, I decided that in the first version there would be ten questions that would not appear randomly (you can see here future planned upgrades), so that the user would get used to the terms faster and learn them as soon as possible. In order to indicate the border between the question,answers, messages in order to make it more readable, I added the lines of stars, dashes. Because this quiz is designed as an educational application. As for the answer, three possibilities are allowed A, B or C, all other entries will cause an invalid entry message (For more look at Testing section)
  • For iterating through the lists of questions and answers, I decided on a "for loop", where I found inspiration in the following project Python quiz game
  • I decided to chain functions for better control of the flow, after talking with the mentor
    Question
  • As I mentioned, this application is intended as an educational one, that's why I decided that for a correctly answered question, the user will receive an example of the use of the term. But in order to motivate users to repeat the game (through repetition one learns), there is no explanation for incorrect answers.
  • To check the accuracy of the results, I defined a simple function with an "if else statement" where the correct and the entered answer are compared, considering it the simplest and most effective solution.
  • While to check the validity of the answer entry, I used a combination of if statements with try /except inspired by the Love Sandwiches Project by Code Institute and Errors and Exceptions
    Invalid input
  • I thought it would be best to display the user's results in tabular form and for the code I used the article How to Create Tables in Python (With Examples) and tabulate library which is installed by entering the following command in the terminal pip install tabulate.
  • Since I wanted the results to be displayed in descending order, I researched and found the following solution itemgetter from operator module to retrieve specific fields from a list with sorted() method (Python sorted()) and to achieve the desired results I added reverse=True so that ranking list is in descending order.
    Table
  • As a final feature, along with the final message to the user I wanted to add the possibility to restart the quiz.
  • Where I decided to use all the concepts used in the previous code
    Restart game

Future Features

  • Colored text with colorama module
  • A random selection of questions
  • Increased number of questions and transferred to a separate file
  • Ability to choose the number of questions
  • Adding strip() method to remove the space and accept input of answers and Yes/No.

Validation and Testing

Validation

Python code passed through Code Institute CI Python Linter shows no errors. Code Institute CI Python Linter

Testing

After validation through Code Institute CI Python Linter, the rest of the testing was done manually in console and on deployed project.
While coding I mostly used the print function to check if I was getting the intended results.

Expected Testing Result Fix Possible upgrade
The opening prompt in the game is: "Do you want to test your knowledge? (Yes / No)" with the expected answer is either "Yes" or "No" (lowercase or uppercase letters are allowed). Any other entry will cause a message "Incorrect entry! Your answer must be Yes or No!" The message will be repeated until the conditions are met. If "Yes" is selected it continues its flow, if "No" is selected it quits the program. I tested the feature by entering various upper and lower case letters, words, numbers, symbols, blank lines, spaces, combinations of all of the above. The program feature behaved as I planned, only "Yes" or "No" input was accepted in all forms except with added space. No fix needed. Adding strip() method to remove the space and accept input.
"Please enter your name:" feature of the program expects the user's name to be entered and all characters, including spaces, are accepted. So that users of the same name could add some symbol for differentiation. I did the testing by entering all possible characters, spaces. Everything was accepted. But for the sake of readability, the number of characters should be limited to about 20 in the future version. No fix needed. Character limit.
The next feature tested is entering answers to questions. Where it is expected to accept A, B or C for input (lowercase or uppercase). An error is expected for every other input: "Invalid entry, your answer must be A, B or C, please try again.". The message will be repeated until the conditions are met. I tested the feature by entering various upper and lower case letters, words, numbers, symbols, blank lines, spaces, combinations of all of the above. The application behaved as I expected, the entries A, B, C were accepted (uppercase and lowercase except with added space). For all others, an invalid input message was output No fix needed. Adding strip() method to remove the space and accept input.
The last question to the user is whether he wants to repeat the game and the possible answers are "Yes" and "No". If "Yes" is selected it continues its flow, if "No" is selected it quits the program. "Please enter your Yes or No!" message is received for all other entries. The message will be repeated until the conditions are met. I did the testing by entering all possible characters, spaces etc. The program feature behaved as I planned, only "Yes" or "No" input was accepted in all forms except with added space. No fix needed. Adding strip() method to remove the space and accept input.

Testing examples:
Test 1
Test 2
Test 3

Bugs

Fixed Bugs

  • Some lines of code were too long, so I was getting an E501 error. Using the recommendations from the article How to Break Long Lines in Python, I break long lines of code, so the error no longer appears.
    Error Example 1

  • After fixing the problem with lines that were too long, the result variable was no longer displayed. The solution was simple, when I brake the line, I forgot to add the prefix f (f-Strings)
    Error Example 2


Deployment

Local Deployment

Requirements

How to Clone

  1. Go to the repository of project

  2. Click on the Code button above the list of files

  3. Choose one of remote URL: HTTPS, SSH, GitHub CLI and click the copy button or download a copy of the project repository and extract the zip file to your base folder.

  4. In your IDE Terminal change the current working directory to the one where you want the clone

  5. Type following code (for example is used GitHub CLI URL) in Git Bash/Terminal of IDE and press Enter:

    git clone https://github.com/radule90/CI_PP_3.git
    
  6. In order to work properly, it needs to be installed tabulate library, type following code in Git Bash/Terminal:

    pip install tabulate
    
  7. You can run the project after you have Python installed, run it on an HTTP server with Python with a command such as:

    python3 run.py
    

How to Fork

  1. Go to the repository of project
  2. Bellow navigation bar on the top of the page in right corner you will locate Fork button
  3. When clicked, you should have a copy of repository in your GitHub

Heroku Deployment

  • A requirements.txt file created with pip freeze > requirements.txt.
  • Create a new Heroku app, select name and region
  • Add Config Var to Heroku settings, where key is PORT and the value is 8000
  • In Settings, set the buildpacks to Python and NodeJS in that order
  • In Deploy section, select the Github repository from the menu
  • Link the Heroku app to the Github repository
  • Deploy the repository
  • Click the View App button to see live version of the project

Credits

  • Code Institute
  • Rory Patrick Sheridan (Mentor) - Great advice and guidance
  • W3Schools - Additional learning resources
  • Bro Code - Python quiz game / Used as a reference to build the app

Tools and Platforms


Content


Media