Python Quiz Game

Source code of Quiz Game in Python

   scoreList = []
def gameKBC(n):
    """Answer the questions asked correctly and win money"""
    questionslist = ["What is the capital city of Pakistan?", 
                "What programming language has the most user-friendly syntax?",
                "What is the chemical composition of water?",
                "Stars are mainly made of?",
                "How old is our universe?"]
    
    optionsList = [["Peshawar", "Karachi", "Lahore", "Islamabad"],
           ["python", "c++", "java", "lisp"],
           ["hydrogen", "oxygen", "hydrogen and oxygen", "nitrogen"],
           ["helium", "hydrogen", "iron", "chromium"],
           ["6000 years", "10,000 years", "1M years", ">13B years"]]
    
    correctOptions = ["4", "1", "3", "2", "4"]
    
    print(f"\nQuestion # {n+1}", questionslist[n])
    
    for i, option in enumerate(optionsList[n]):
        print(f"{i+1}- {option}")
         
    score = 0
    userAnswer = input(">>> ")
    if userAnswer == correctOptions[n]:
        score += 1
        print("Correct answer!")
    else:
        print("Wrong answer")
        
    scoreList.append(score)    
    
# print(gameKBC.__doc__)

print("\n>>> Welcome to Kon Banega Crorepati Game<<<\n\tAnswer 5 questions CORRECTLY and Win 5 Crore Rupees.\n\tAre you ready (y/n)?")
yn = input(">>> ")
if yn == "y":
    print("\nWelcome to the Game.")
    for i in range(5):
        gameKBC(i)
        print(scoreList)
        finalScore = 0
        for i in scoreList:
            finalScore += i
    print("You final score is", finalScore)
    if finalScore == 0:
        print("Sorry, ALl your answers are wrong")
    else:
        print(f"Congrats! You won {finalScore} Crore Rupees\n")

    

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes