Topics in CS: Ο-thon
Building A Trivia Game
Q1 2023
In this project, you will have an opportunity to create a trivia game in a topic of your choice. For this project, you must create 4οΈβ£ four trivia questions 4οΈβ£ with some type of response for π΅ incorrect π΅ or π correct answers π. You will decide on the πͺ© theme πͺ©

π 0: Goals & Review π
This lesson has three main goals. Please turn in the following:
- βοΈ Triva game with 4 questions (repl.it) βοΈ
- βοΈ 3 Peer reviews: to & from (you make doc) βοΈ
- ποΈ 5 descriptive ideas for final project (you make doc) ποΈ
πͺοΈ Coding Review πͺοΈ
In our previous sessions, we have examined how we can use conditional statements to check for true or false. Here is an example:
city = input("What city is Riverdale located in?")
if city == "New York City" or city == "NYC":
print("correct")
else:
print("wrong")
We used the βorβ & "and" statements to allow for as many possible correct solutions as possible. In the example above either New York City or NYC would work as correct answers. All other answers would be incorrect and fall into the else clause. π€
city = input("What city is Riverdale located in?")
name = input("What is your name?")
if city == "New York City" or city == "NYC" or city == "Bronx":
print("correct")
elif city == "NYC" and name == "Lila":
print("You must be cool")
else:
print("wrong")
π 1: Learn π
First, create a new project called trivia_game. Next, research and try to use the .lower(), .strip(), and .find() to help you learn how to control text input. π οΈ Have an example of each in your script. Make sure you know Methods and Arguments. This is a huge part of the course.
The Actual Lesson
Methods & Arguments
π οΈ Method π οΈ
Imagine you have a toy robot π€. This robot can do different things like walk πΆ, dance π, and sing π€. Each of these actions is like a "method" for the robot. In Python, objects (like our robot) can have methods that allow them to do specific tasks. In Python, you can chain methods together
# Calling a Method
robot.dance()
# Chaining methods
robot.dance().backfilp()
answer = input("what is the answer?")
anwser.find(string.upper())
Here, `dance` is a method that makes the robot dance.
π Argument π
Now, let's say your robot can also paint π¨, but it needs to know which color to use. You tell the robot the color by giving it a small box π with the paint inside. This box is like an "argument" you give to the method.
robot.paint("blue")
Here, `"blue"` is the argument you're giving to the `paint` method to tell the robot which color to use.
So, in simple terms:
- A π οΈ method π οΈ is an action or task that something can do.
- An π argument π is extra information you give to help the method do its job.
I hope that helps! π
Learn New Methods
The lower() method
returns a string where all characters are lower case. π
city = "New York City"
print(city.lower()) #prints new york city
The strip() method
removes any leading (spaces at the beginning) and trailing (spaces at the end) characters (space is the default leading character to remove) π«
city = " New York City "
print(city.strip())
# removes the spaces on either side of the string
The find() method
finds the first occurrence of the specified value. The find() method returns -1 if the value is not found. π
python
city = "New York City"
print(city.find("York")) #prints 4-> the index in which it found York
# You can even combine these methods. π
βοΈ 2: Build βοΈ
Project π
When creating your πͺ© Trivia game πͺ©, you want to make it as accurate as possible for the users to play the game. Using βorβ statements will help you add correct answers.
Employing methods such as .lower(), .strip(), and .find() to help us and developers to anticipate users' responses by ignoring case, extra spaces on the ends of the string, or finding a specific term in the string. π²
We also added some cool tricksπ
Time
time.sleep(0.5) #pause the program for 0.5 seconds
ASCII Art
Use ASCII characters to create drawings or designs in your game!
print("""
+----------------+
| WELCOME |
+----------------+
""")
Try to chain together .find(), .strip(), and .lower()
π‘ 3: Peer Review π‘
Peer-review is the crux of all science
First, gain and give 3 Peer reviews. In this class, peer-review is simple. Give a π glow π, πΏ grow πΏ, and an π¬ insight π¬ as a comment. Less than a paragraph is not helpful, more than a few paragraphs is scary.
Code Review Example
def circle_area(radius):
pi = 3.14
return pi * radius * radius
Peer Review:
π Glow π:
Great job on keeping the function concise and to the point! The function name circle_area is descriptive, and it's clear what the function is intended to do. Using a clear variable name like radius also makes the code easy to understand.
πΏ Grow πΏ:
Consider using the built-in math.pi instead of hardcoding the value of pi to 3.14. This would make the calculation more accurate and also show that you're utilizing Python's built-in libraries effectively.
π¬ Insight π¬:
Did you know that the formula you used is derived from the integral of r with respect to ΞΈ from 0 to 2Ο in polar coordinates? It's fascinating how math and programming often intersect in such ways!
π¬ 4: Research Guide π¬
This guide will help you explore different areas of Python to inspire your final project. Today, you will pick β five β potential project ideas you would want to follow up on. This should include the main topic (all listed below ), and a description of the project.
Example
Main Topic: Raspberry Pi and Python
Description:
I will turn a Raspberry Pi into a live webcam using Python! This project will involve connecting a USB webcam or Pi Camera to a Raspberry Pi and setting up a Python script to stream video over the internet. I can further enhance this by adding features like motion detection, time-lapse photography, or even facial recognition using libraries like OpenCV!
Main Topics
1. Basics of Python
- Python Official Documentation
- Real Python - Basics
- Python Crash Course
2. Game Development
- Pygame Tutorials
- Making Games with Python & Pygame (Book)
3. Web Development
- Flask: Micro Web Framework
- Django: High-level Web Framework
4. Data Visualization
- Matplotlib Tutorials
- Seaborn: Statistical Data Visualization
5. Robotics and Hardware
- Python with Raspberry Pi
- MicroPython: Python for Microcontrollers
6. Music and Sound
- PyDub: Audio Manipulation with Python
- Sonic Pi: Code Music
π 5 Turning In Work π
π Try a Stretch goal(s) π
π― Can you add a score to the game? 1 point if the user get the correct answer. 0 or -1 points if the user does not get the correct answer. π
If you add a score to the game, π buzz feed quiz π it: depending on the score, print a specific phrase. For instance, if the user gets all four questions correct, print
βYou are amazing! You got all 4 correct!β π
How To Turn IN π
Once done with your code & peer-reviews, email the replit link which will have your other links inside of it as a comments
# www.peer_review_doc.com
# www.my_project_ideas.com
print("this is my repl.it code")
print("I turn in the repl.it link")
The peer_review.doc should contain the reviews you gave & recieved. I'd suggest using a table to organize this data.
- You have the entire session and homework to work on the project. It is due for homework by next class.
- Test your project with a classmate to verify that the trivia game works effectively and that you have anticipated the various answers from the user.
- Remember to copy the Academic Honesty statement into your work and submit your project. π€
Bee Who You Want to Bee
Academic Honesty Statement for Computer Science Department π
Please submit this assignment with your name and a copy of this text.
I have neither given nor received improper aid in the preparation of this computer science assignment or in the completion of this code. Unless properly attributed to others, the work is exclusively my own.
Signed: (type your name here acknowledging this statement) βοΈ