What's new

Python Python Tkinter Show Score

PHC - Margauxein

Forum Veteran
Elite
Joined
Mar 23, 2019
Posts
1,515
Solutions
10
Reaction
2,164
Points
663
Age
20
Baka pwede po pahelp sa score nalang po kulang kapag tapos na mag sagot yung user dapat po lalabas yung score eh

Code:
from tkinter import *
from tkinter import messagebox
import random

window = Tk()
window.title("Quiz Game")
window.geometry("800x400")
window.configure(background="Light Gray")


def quit_game():
    user_screen.place_forget()
    root.pack()


def start_game():
    user_screen.place_forget()
    root.pack()

    score = 0

    def next_question():
        questions = [
            {
                "question": "Who found Diariong Tagalog?",
                "options": ["A. Juan Luna", "B. Marcelo del Pilar", "C. Pedro Laktaw", "D. Gregorio Sanciano"],
                "answer": "B. Marcelo del Pilar"
            },
            {
                "question": "The Political section of the Association Hispano-Filipino was under the charge of:",
                "options": ["A. Jose Rizal", "B. Marcelo del Pilar", "C. Dominador Gomez", "D. Tomas Arejola"],
                "answer": "B. Marcelo del Pilar"
            },
            {
                "question": "Based on the plan proposed by whom was The Malolos Constitution drafted?",
                "options": ["A. Paterno", "B. Calderon", "C. Mabini"],
                "answer": "B. Calderon"
            },
            {
                "question": "Taga-Ilog was the pen name which was associated with:",
                "options": ["A. Juan Luna", "B. Mariano Ponce", "C. Jose Ma. Panganiban", "D. Antonio Luna"],
                "answer": "D. Antonio Luna"
            },
            {
                "question": "Tell the name of the president of the Association La Solidaridad.",
                "options": ["A. Galiciano Apacible", "B. Mariano Ponce", "C. Jose Ma. Panganiban",
                            "D. Manuel Sta. Maria"],
                "answer": "A. Galiciano Apacible"
            },
            {
                "question": "Who was the founder of the KKK?",
                "options": ["A. Emilio Aguinaldo", "B. Jose Rizal", "C. Andres Bonifacio", "D. Confederate Army"],
                "answer": "C. Andres Bonifacio"
            },
            {
                "question": "Considered as the first Philippine hero.?",
                "options": ["A. King Philip II of Spain", "B. Lapu-lapu", "C. Jose Rizal", "D. Ferdinand Magellan"],
                "answer": "B. Lapu-lapu"
            },
            {
                "question": "Where was the Rizal's novel 'Noli Me Tangere' published?",
                "options": ["A. Paris", "B. Manila", "C. Berlin", "D. Tokyo"],
                "answer": "C. Berlin"
            },
            {
                "question": "What is considered the earliest form of writing in the Philippines?",
                "options": ["A. Kuhitan", "B. Buhid", "C. Baybayin", "D. Tagbanua"],
                "answer": "C. Baybayin"
            },
            {
                "question": "Who created the designs for the Philippine national flag?",
                "options": ["A. Emilio Aguinaldo", "B. Marcella Agoncillo", "C. Gabriella Silang", "D. Tandang Sora"],
                "answer": "A. Emilio Aguinaldo"
            }
        ]

        question = random.choice(questions)

        global q
        global options
        q = question["question"]
        options = question["options"]
        global correct_answer
        correct_answer = question["answer"]

        q_label.config(text=q)

        option_1.config(text=options[0])
        option_2.config(text=options[1])
        option_3.config(text=options[2])
        option_4.config(text=options[3])

    def check_answer(answer):
        global score
        if (answer == correct_answer):
            score += 1
            messagebox.showinfo("Correct Answer", "Correct! Nicely Done")
        else:
            messagebox.showerror("Wrong Answer", "Incorrect! Better luck next time!")

        next_question()

    q_label = Label(window, text="", font=("Helvetica", 16), bg='#FFF5EE')
    q_label.pack()

    option_1 = Button(window, text="", font=("Helvetica", 14), bg='#EEE5DE', width=20,
                      command=lambda: check_answer(options[0]))
    option_1.pack()

    option_2 = Button(window, text="", font=("Helvetica", 14), bg='#EEE5DE', width=20,
                      command=lambda: check_answer(options[1]))
    option_2.pack()

    option_3 = Button(window, text="", font=("Helvetica", 14), bg='#EEE5DE', width=20,
                      command=lambda: check_answer(options[2]))
    option_3.pack()

    option_4 = Button(window, text="", font=("Helvetica", 14), bg='#EEE5DE', width=20,
                      command=lambda: check_answer(options[3]))
    option_4.pack()

    next_question()


user_screen = Frame(bg="Light Gray")
user_screen.place(relx=0.5, rely=0.5, anchor=CENTER)
intro_message = Label(user_screen, width=60, font=("Arial", 20), fg='Black', bg='Yellow', bd=5, text=">>WIZARD GAME<<")
intro_message.pack()
label = Label(user_screen, text="", bg="Light Gray", fg="Light Gray", padx=50, pady=50).pack()
play_b = Button(user_screen, font=("Arial", 13, "bold"), text="Play Game", command=start_game)
play_b.pack()
ins = Button(user_screen, font=("Arial", 13, "bold"), text="Quit Game", command=exit)
ins.pack()
root = Frame(window, bg='cadet blue')
root.pack_forget()

window.mainloop()
 
Last edited:
Python:
from tkinter import *
from tkinter import messagebox
import random

window = Tk()
window.title("Quiz Game")
window.geometry("800x400")
window.configure(background="Light Gray")

score = 0

def quit_game():
user_screen.place_forget()
root.pack()

def start_game():
user_screen.place_forget()
root.pack()

Python:
def next_question():
    questions = [
        {
            "question": "Who found Diariong Tagalog?",
            "options": ["A. Juan Luna", "B. Marcelo del Pilar", "C. Pedro Laktaw", "D. Gregorio Sanciano"],
            "answer": "B. Marcelo del Pilar"
        },
        {
            "question": "The Political section of the Association Hispano-Filipino was under the charge of:",
            "options": ["A. Jose Rizal", "B. Marcelo del Pilar", "C. Dominador Gomez", "D. Tomas Arejola"],
            "answer": "B. Marcelo del Pilar"
        },
        {
            "question": "Based on the plan proposed by whom was The Malolos Constitution drafted?",
            "options": ["A. Paterno", "B. Calderon", "C. Mabini"],
            "answer": "B. Calderon"
        },
        {
            "question": "Taga-Ilog was the pen name which was associated with:",
            "options": ["A. Juan Luna", "B. Mariano Ponce", "C. Jose Ma. Panganiban", "D. Antonio Luna"],
            "answer": "D. Antonio Luna"
        },
        {
            "question": "Tell the name of the president of the Association La Solidaridad.",
            "options": ["A. Galiciano Apacible", "B. Mariano Ponce", "C. Jose Ma. Panganiban",
                        "D. Manuel Sta. Maria"],
            "answer": "A. Galiciano Apacible"
        },
        {
            "question": "Who was the founder of the KKK?",
            "options": ["A. Emilio Aguinaldo", "B. Jose Rizal", "C. Andres Bonifacio", "D. Confederate Army"],
            "answer": "C. Andres Bonifacio"
        },
        {
            "question": "Considered as the first Philippine hero.?",
            "options": ["A. King Philip II of Spain", "B. Lapu-lapu", "C. Jose Rizal", "D. Ferdinand Magellan"],
            "answer": "B. Lapu-lapu"
        },
        {
            "question": "Where was the Rizal's novel 'Noli Me Tangere' published?",
            "options": ["A. Paris", "B. Manila", "C. Berlin", "D. Tokyo"],
            "answer": "C. Berlin"
        },
        {
            "question": "What is considered the earliest form of writing in the Philippines?",
            "options": ["A. Kuhitan", "B. Buhid", "C. Baybayin", "D. Tagbanua"],
            "answer": "C. Baybay

Try nyo lang Po d ako expert eh baka gumana✌️
 
Try nyo lang Po d ako expert eh baka gumana✌️
maraming salamat lods yung ganito po sana lods oh yung after mag sagot lalabas po yung final score

Screenshot-2021-12-11-014531.png
 

Attachments

maraming salamat lods yung ganito po sana lods oh yung after mag sagot lalabas po yung final score

View attachment 2415072
Python:
# Set the number of questions and the number of correct answers
num_questions = 10
num_correct = 7

# Calculate the quiz score as a percentage
score = (num_correct / num_questions) * 100

# Display the quiz results
print("Quiz results:")
print("Number of questions:", num_questions)
print("Number of correct answers:", num_correct)
print("Score: {:.1f}%".format(score))

# Display a message based on the quiz score
if score >= 90:
    print("Excellent performance!")
elif score >= 80:
    print("Good job!")
elif score >= 70:
    print("Nice work!")
elif score >= 60:
    print("You passed!")
else:
    print("Unfortunately, you did not pass the quiz.")


Try e modify lods d kung Mali man to pasensya na d ako programming expert good luck sa journey mo✌️✌️

maraming salamat lods yung ganito po sana lods oh yung after mag sagot lalabas po yung final score

View attachment 2415072

Python:
# Quiz program

# Initialize variables
score = 0
num_correct = 0
num_incorrect = 0

# Questions and answers
questions = [
    {
        "question": "What is the capital of France?",
        "choices": ["Paris", "London", "Rome", "Madrid"],
        "correct": "Paris"
    },
    {
        "question": "What is the largest planet in the solar system?",
        "choices": ["Earth", "Jupiter", "Mars", "Saturn"],
        "correct": "Jupiter"
    },
    {
        "question": "What is the currency of Japan?",
        "choices": ["Euro", "Dollar", "Yen", "Pound"],
        "correct": "Yen"
    }
]

# Ask questions
for question in questions:
    print(question["question"])
    for i, choice in enumerate(question["choices"]):
        print(f"{i+1}. {choice}")
    answer = input("Enter your answer: ")

    # Check if answer is correct
    if answer == question["correct"]:
        print("Correct!")
        num_correct += 1
        score += 1
    else:
        print("Incorrect.")
        num_incorrect += 1

# Calculate score
total_questions = len(questions)
score_percent = score / total_questions * 100

# Print results
print(f"Score: {score_percent:.0f}%")
print(f"Correct: {num_correct}")
print(f"Incorrect: {num_incorrect}")

Baka mag ka idea ka Dyan lods
 
Last edited:
Back
Top