Create your Own Quiz Program in Python || Python


In this we are going to see a basic program of quiz using dictionary in Python Programming Language.



ques = {
    1:{
        "question1": "What is the capital of India?",
        "options": ["New Delhi", "Mumbai", "Chennai", "Kolkata"],
        "answer": "New Delhi"
    },
    2:{
        "question2": "Who is the Prime Minister of India?",
        "options": ["Narendra Modi", "Rahul Gandhi", "Sonia Gandhi", "Manmohan Singh"],
        "answer": "Narendra Modi"
    },
    3:{
        "question3": "Which is the largest country in the world?",
        "options": ["India", "China", "Russia", "United States"],
        "answer": "Russia"
    },
}

def quiz():
    print("Hello User, Welcome to Quiz.")
    print("You have to answer 3 questions. Choose the correct option no out of the given options: ")
    print("Good Luck!")
    print("\n")
    for i in ques:
        print(ques[i]["question" + str(i)])
        for j in ques[i]["options"]:
            print(j)
        opt = int(input("Enter your answer: "))
        ans = ques[i]["options"][opt - 1]
        if ans == ques[i]["answer"]:
            print("Correct Answer!")
        else:
            print("Wrong Answer!")
    print("\n")
    print("Thank You For Playing.")

quiz()

# Coded By DHIRAJ SHELKE


#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post