Skip to main content

Command Palette

Search for a command to run...

Day-27 Exercise-Game

Updated
2 min read
Day-27 Exercise-Game
C
I am Data Science student, has a little bit knowledge on Web Development. I also love writing and editing as my hobby. Passionate to explore the world.

Create a program capable of displaying questions to the user like KBC. Use List data type to store the questions and their correct answers. Display the final amount the person is taking home after playing the game.

Answer

# KBC Quiz Game

questions = [
    ["What is the capital of Pakistan?",
     "A. Karachi", "B. Islamabad", "C. Lahore", "D. Peshawar", "B"],

    ["Which planet is known as the Red Planet?",
     "A. Venus", "B. Jupiter", "C. Mars", "D. Saturn", "C"],

    ["Who is known as the Father of Computers?",
     "A. Charles Babbage", "B. Newton", "C. Einstein", "D. Tesla", "A"],

    ["What is the largest ocean on Earth?",
     "A. Atlantic", "B. Indian", "C. Arctic", "D. Pacific", "D"],

    ["How many continents are there in the world?",
     "A. 5", "B. 6", "C. 7", "D. 8", "C"]
]

prize_money = [1000, 5000, 10000, 50000, 100000]

amount_won = 0

print("Welcome to KBC!\n")

for i in range(len(questions)):
    q = questions[i]

    print(f"\nQuestion {i + 1} for Rs. {prize_money[i]}")
    print(q[0])

    for option in q[1:5]:
        print(option)

    answer = input("Enter your answer (A/B/C/D): ").upper()

    if answer == q[5]:
        print("Correct Answer!")
        amount_won = prize_money[i]
    else:
        print("Wrong Answer!")
        print(f"The correct answer was {q[5]}")
        break

print("\nGame Over!")
print("You are taking home Rs.", amount_won)

Output:

Welcome to KBC!

Question 1 for Rs. 1000
What is the capital of Pakistan?
A. Karachi
B. Islamabad
C. Lahore
D. Peshawar
Enter your answer (A/B/C/D): B
Correct Answer!

...

Game Over!
You are taking home Rs. 100000

100DaysofPython

Part 28 of 35

This series is for beginners in which we explore python language along with how it is used in data science and do some exercises and some python related projects.

Up next

Day-28 f-strings

String formatting in python String formatting can be done in python using the format method. txt = "For only {price:.2f} dollars!" print(txt.format(price = 49)) f-strings in python It is a new string