-
-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding in a few more tests #35
Open
kelmryan
wants to merge
16
commits into
Ditectrev:main
Choose a base branch
from
kelmryan:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+9,350
−7,264
Open
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7755d37
resolved 4th
kelmryan 7b32a96
resolved 4th
kelmryan 62bf0c8
adding additional answers
kelmryan e009da3
resolved 3rd
kelmryan a27ceed
resolved 3rd
kelmryan 951ebd1
resolved 3rd
kelmryan 189c3cc
resolved 3rd
kelmryan da4e413
Add: Table of Contents for v2.0.0
danieldanielecki 02b9f21
Improve: minor formatting
danieldanielecki 6d63c10
resolved 3rd
kelmryan 2a6a73b
resolved 3rd
kelmryan 4b77344
resolved 4th
kelmryan 6603d99
resolved 4th
kelmryan 1836e01
resolved 3rd
kelmryan 3fe12cf
adding new pythong
kelmryan eee99b1
created counter
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import tkinter as tk | ||
from tkinter import messagebox | ||
import os | ||
|
||
# Questions and answers | ||
def load_questions_from_readme(): | ||
questions = [] | ||
if os.path.exists("README.md"): | ||
with open("README.md", "r") as file: | ||
lines = file.readlines() | ||
question = None | ||
options = [] | ||
correct = None | ||
for line in lines: | ||
line = line.strip() | ||
if line.startswith("###"): | ||
if question: | ||
questions.append({"question": question, "options": options, "correct": correct}) | ||
question = line[3:].strip() | ||
options = [] | ||
correct = None | ||
elif line.startswith("- [ ]"): | ||
options.append(line[5:].strip()) | ||
elif line.startswith("- [x]"): | ||
options.append(line[5:].strip()) | ||
correct = len(options) - 1 | ||
if question: | ||
questions.append({"question": question, "options": options, "correct": correct}) | ||
return questions | ||
|
||
questions = load_questions_from_readme() | ||
|
||
class QuizApp: | ||
def __init__(self, root): | ||
self.root = root | ||
self.root.title("Quiz App") | ||
self.current_question = 0 | ||
self.score_correct = 0 | ||
self.score_incorrect = 0 | ||
self.create_widgets() | ||
|
||
def create_widgets(self): | ||
self.question_label = tk.Label(self.root, text=questions[self.current_question]["question"], wraplength=400, font=("Helvetica", 12, "bold")) | ||
self.question_label.grid(row=0, column=0, columnspan=2, pady=20) | ||
|
||
self.var = tk.IntVar() | ||
self.var.set(-1) | ||
|
||
self.option_buttons = [] | ||
for idx, option in enumerate(questions[self.current_question]["options"]): | ||
btn = tk.Radiobutton(self.root, text=option, variable=self.var, value=idx, wraplength=400) | ||
btn.grid(row=1+idx, column=0, columnspan=2, sticky="w", padx=20, pady=5) | ||
self.option_buttons.append(btn) | ||
|
||
button_frame = tk.Frame(self.root) | ||
button_frame.grid(row=1+len(questions[self.current_question]["options"]), column=0, columnspan=2, pady=20) | ||
|
||
self.submit_button = tk.Button(button_frame, text="Submit", command=self.check_answer) | ||
self.submit_button.grid(row=0, column=0, padx=10, pady=10) | ||
|
||
self.reset_button = tk.Button(button_frame, text="Reset", command=self.reset_answer) | ||
self.reset_button.grid(row=0, column=1, padx=10, pady=10) | ||
|
||
self.next_button = tk.Button(button_frame, text="Next", command=self.next_question) | ||
self.next_button.grid(row=0, column=2, padx=10, pady=10) | ||
|
||
self.back_button = tk.Button(button_frame, text="Back", command=self.previous_question, state="disabled") | ||
self.back_button.grid(row=0, column=3, padx=10, pady=10) | ||
|
||
score_frame = tk.Frame(self.root) | ||
score_frame.grid(row=2+len(questions[self.current_question]["options"]), column=0, columnspan=2, pady=20) | ||
|
||
self.correct_label = tk.Label(score_frame, text=f"Correct: {self.score_correct}", fg="green") | ||
self.correct_label.grid(row=0, column=0, padx=10) | ||
|
||
self.incorrect_label = tk.Label(score_frame, text=f"Incorrect: {self.score_incorrect}", fg="red") | ||
self.incorrect_label.grid(row=0, column=1, padx=10) | ||
|
||
def next_question(self): | ||
self.current_question += 1 | ||
if self.current_question >= len(questions): | ||
messagebox.showinfo("Quiz Completed", f"Your score is {self.score_correct}/{len(questions)}") | ||
self.root.quit() | ||
else: | ||
self.question_label.config(text=questions[self.current_question]["question"]) | ||
self.var.set(-1) | ||
for idx, option in enumerate(questions[self.current_question]["options"]): | ||
self.option_buttons[idx-1].config(text=option, fg="black") | ||
self.submit_button.config(state="normal") | ||
self.back_button.config(state="normal" if self.current_question > 0 else "disabled") | ||
|
||
def previous_question(self): | ||
self.current_question -= 1 | ||
self.question_label.config(text=questions[self.current_question]["question"]) | ||
self.var.set(-1) | ||
for idx, option in enumerate(questions[self.current_question]["options"]): | ||
self.option_buttons[idx].config(text=option, fg="black") | ||
self.submit_button.config(state="normal") | ||
self.back_button.config(state="normal" if self.current_question > 0 else "disabled") | ||
|
||
def reset_answer(self): | ||
self.var.set(-1) | ||
for btn in self.option_buttons: | ||
btn.config(fg="black") | ||
self.submit_button.config(state="normal") | ||
self.next_button.config(state="disabled") | ||
|
||
def check_answer(self): | ||
selected = self.var.get() | ||
if selected == -1: | ||
messagebox.showwarning("Warning", "Please select an answer.") | ||
return | ||
|
||
if selected == questions[self.current_question]["correct"]: | ||
self.option_buttons[selected].config(fg="green") | ||
self.score_correct += 1 | ||
else: | ||
self.option_buttons[selected].config(fg="red") | ||
self.score_incorrect += 1 | ||
|
||
self.correct_label.config(text=f"Correct: {self.score_correct}") | ||
self.incorrect_label.config(text=f"Incorrect: {self.score_incorrect}") | ||
|
||
self.next_button.config(state="normal") | ||
|
||
if __name__ == "__main__": | ||
root = tk.Tk() | ||
app = QuizApp(root) | ||
root.mainloop() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need the star here?:)