diff --git a/.gitignore b/.gitignore index 600bbb9..4b11f84 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -# Ignore Markdown formatting being inconsistent with markdownlint -.prettierignore - # Ignore virtual environments venv diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..42bb3bb --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +*/*.md \ No newline at end of file diff --git a/Day 17/README.md b/Day 17/README.md new file mode 100644 index 0000000..676760a --- /dev/null +++ b/Day 17/README.md @@ -0,0 +1,6 @@ +# Day 17 - Implementing Classes + +- Learned the structure of creating a class with its attributes, methods, and how to initialize objects +- Created a trivia quiz game, with some neat questions from [opentdb](https://opentdb.com/). + +![Day_17_Trivia](https://user-images.githubusercontent.com/30333942/128618891-34c051c8-b0fe-4982-8852-536a3a9bf311.gif) diff --git a/Day 17/day-17-start/main.py b/Day 17/day-17-start/main.py new file mode 100644 index 0000000..576a9bd --- /dev/null +++ b/Day 17/day-17-start/main.py @@ -0,0 +1,22 @@ +class User: + + def __init__(self, user_id, username): + self.id = user_id + self.username = username + self.followers = 0 + self.following = 0 + + def follow(self, user): + user.followers += 1 + self.following += 1 + + +user_1 = User("001", "mueez") +# user_1.id = "001" # like self.id in init function, but just for this user_1 object if not in init +# user_1.username = "mueez" +user_2 = User("002", "another_user") +user_1.follow(user_2) +print(user_1.followers) +print(user_2.followers) +print(user_1.following) +print(user_2.following) diff --git a/Day 17/quiz-game-start/data.py b/Day 17/quiz-game-start/data.py new file mode 100644 index 0000000..ac7c074 --- /dev/null +++ b/Day 17/quiz-game-start/data.py @@ -0,0 +1,82 @@ +question_data = [ + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "easy", + "question": "Linus Torvalds created Linux and Git.", + "correct_answer": "True", + "incorrect_answers": ["False"], + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "easy", + "question": "The programming language Python is based off a modified version of JavaScript.", + "correct_answer": "False", + "incorrect_answers": ["True"], + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "easy", + "question": "The logo for Snapchat is a Bell.", + "correct_answer": "False", + "incorrect_answers": ["True"], + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "easy", + "question": "RAM stands for Random Access Memory.", + "correct_answer": "True", + "incorrect_answers": ["False"], + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "easy", + "question": "Ada Lovelace is often considered the first computer programmer.", + "correct_answer": "True", + "incorrect_answers": ["False"], + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "easy", + "question": "In most programming languages, the operator ++ is equivalent to the statement += 1.", + "correct_answer": "True", + "incorrect_answers": ["False"], + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "easy", + "question": "The Windows 7 operating system has six main editions.", + "correct_answer": "True", + "incorrect_answers": ["False"], + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "easy", + "question": "The NVidia GTX 1080 gets its name because it can only render at a 1920x1080 screen resolution.", + "correct_answer": "False", + "incorrect_answers": ["True"], + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "easy", + "question": "Linux was first created as an alternative to Windows XP.", + "correct_answer": "False", + "incorrect_answers": ["True"], + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "easy", + "question": "The Python programming language gets its name from the British comedy group Monty Python.", + "correct_answer": "True", + "incorrect_answers": ["False"], + }, + ] \ No newline at end of file diff --git a/Day 17/quiz-game-start/main.py b/Day 17/quiz-game-start/main.py new file mode 100644 index 0000000..2d85e29 --- /dev/null +++ b/Day 17/quiz-game-start/main.py @@ -0,0 +1,17 @@ +from question_model import Question +from data import question_data +from quiz_brain import QuizBrain + +question_bank = [] + +for question in question_data: + question_text = question["question"] + question_answer = question["correct_answer"] + new_question = Question(question_text, question_answer) + question_bank.append(new_question) + +quiz = QuizBrain(question_bank) +while quiz.still_has_questions(): + quiz.next_question() +print("You've completed the quiz!") +print(f"Your final score was: {quiz.score}/{len(quiz.question_list)}.") diff --git a/Day 17/quiz-game-start/question_model.py b/Day 17/quiz-game-start/question_model.py new file mode 100644 index 0000000..6a18a2f --- /dev/null +++ b/Day 17/quiz-game-start/question_model.py @@ -0,0 +1,4 @@ +class Question: + def __init__(self, text, answer): + self.text = text + self.answer = answer diff --git a/Day 17/quiz-game-start/quiz_brain.py b/Day 17/quiz-game-start/quiz_brain.py new file mode 100644 index 0000000..906aec7 --- /dev/null +++ b/Day 17/quiz-game-start/quiz_brain.py @@ -0,0 +1,25 @@ +class QuizBrain: + def __init__(self, question_list): + self.question_number = 0 + self.question_list = question_list + self.score = 0 + + def still_has_questions(self): + return self.question_number < len(self.question_list) + + def next_question(self): + current_question = self.question_list[self.question_number] + self.question_number += 1 + user_answer = input( + f"Q.{self.question_number}: {current_question.text} (True/False)?: " + ) + self.check_answer(user_answer, current_question.answer) + + def check_answer(self, user_answer, correct_answer): + if user_answer.lower() == correct_answer.lower(): + self.score += 1 + print("You got it right!") + else: + print("That's wrong.") + print(f"The correct answer was: {correct_answer}.") + print(f"Your current score is: {self.score}/{self.question_number}.\n")