KBC game using Python

Kaun Banega Crorepati (KBC) is a popular Indian quiz show based on "Who Wants to Be a Millionaire." In this article, we'll create a simplified version of the KBC game using Python programming concepts like loops, conditionals, and user input.

What is KBC?

In the KBC game, contestants answer multiple-choice questions to win prize money that increases with each correct answer. The game continues until the player answers incorrectly or completes all questions successfully.

Key Components

Our KBC game implementation uses these Python concepts:

  • Variables ? Store questions, options, correct answers, and prize money

  • Lists and Dictionaries ? Organize question data efficiently

  • User Input ? Read player's answer choices using input()

  • Conditional Statements ? Check if answers are correct using if/else

  • Loops ? Iterate through questions using for or while loops

Algorithm

  1. Initialize prize money to zero

  2. Create a list of questions with options and correct answers

  3. Display each question with multiple-choice options

  4. Read and validate user's answer

  5. Check if the answer matches the correct option

  6. Update prize money for correct answers

  7. End game on wrong answer or completion

  8. Display final prize money earned

Method 1: Using For Loop

This approach iterates through all questions sequentially ?

import random

# Set initial prize money
prize_money = 0

# Create questions with options and correct answers
questions = [
    {
        "question": "What is the capital of India?",
        "options": ["1. Delhi", "2. Mumbai", "3. Kolkata", "4. Chennai"],
        "answer": 1
    },
    {
        "question": "Which planet is known as the Red Planet?",
        "options": ["1. Jupiter", "2. Venus", "3. Mars", "4. Saturn"],
        "answer": 3
    },
    {
        "question": "Who painted the Mona Lisa?",
        "options": ["1. Vincent van Gogh", "2. Pablo Picasso", "3. Leonardo da Vinci", "4. Claude Monet"],
        "answer": 3
    }
]

# Shuffle questions for variety
random.shuffle(questions)

# Iterate through questions
for question in questions:
    print(f"\n{question['question']}")
    for option in question["options"]:
        print(option)
    
    try:
        user_answer = int(input("Enter your answer (1-4): "))
        
        if user_answer == question["answer"]:
            print("Correct answer!")
            prize_money += 1000
            print(f"Prize money: ?{prize_money}")
        else:
            print(f"Wrong answer! The correct answer was option {question['answer']}.")
            break
    except ValueError:
        print("Invalid input! Game over.")
        break

print(f"\nFinal Prize Money: ?{prize_money}")
Which planet is known as the Red Planet?
1. Jupiter
2. Venus
3. Mars
4. Saturn
Enter your answer (1-4): 3
Correct answer!
Prize money: ?1000

What is the capital of India?
1. Delhi
2. Mumbai
3. Kolkata
4. Chennai
Enter your answer (1-4): 1
Correct answer!
Prize money: ?2000

Who painted the Mona Lisa?
1. Vincent van Gogh
2. Pablo Picasso
3. Leonardo da Vinci
4. Claude Monet
Enter your answer (1-4): 3
Correct answer!
Prize money: ?3000

Final Prize Money: ?3000

Method 2: Using While Loop

This approach provides more control over the game flow and allows for additional features ?

# Set initial values
prize_money = 0
question_index = 0
game_over = False

# Create questions list
questions = [
    {
        "question": "What is the capital of India?",
        "options": ["1. Delhi", "2. Mumbai", "3. Kolkata", "4. Chennai"],
        "answer": 1
    },
    {
        "question": "Which planet is known as the Red Planet?",
        "options": ["1. Jupiter", "2. Venus", "3. Mars", "4. Saturn"],
        "answer": 3
    },
    {
        "question": "Who painted the Mona Lisa?",
        "options": ["1. Vincent van Gogh", "2. Pablo Picasso", "3. Leonardo da Vinci", "4. Claude Monet"],
        "answer": 3
    }
]

# Game loop
while not game_over and question_index < len(questions):
    current_question = questions[question_index]
    
    print(f"\nQuestion {question_index + 1}: {current_question['question']}")
    for option in current_question["options"]:
        print(option)
    
    try:
        user_answer = int(input("Enter your answer (1-4): "))
        
        if user_answer == current_question["answer"]:
            print("Correct answer!")
            prize_money += 1000
            print(f"Prize money: ?{prize_money}")
            question_index += 1
        else:
            print(f"Wrong answer! The correct answer was option {current_question['answer']}.")
            game_over = True
    except ValueError:
        print("Invalid input! Please enter a number between 1-4.")
        game_over = True

# Check if player completed all questions
if question_index == len(questions):
    print("\nCongratulations! You answered all questions correctly!")

print(f"Final Prize Money: ?{prize_money}")
Question 1: What is the capital of India?
1. Delhi
2. Mumbai
3. Kolkata
4. Chennai
Enter your answer (1-4): 1
Correct answer!
Prize money: ?1000

Question 2: Which planet is known as the Red Planet?
1. Jupiter
2. Venus
3. Mars
4. Saturn
Enter your answer (1-4): 2
Wrong answer! The correct answer was option 3.
Final Prize Money: ?1000

Comparison

Method Advantages Best For
For Loop Simple, clean code Fixed number of questions
While Loop More control, flexible conditions Dynamic game flow, additional features

Conclusion

Creating a KBC game in Python demonstrates fundamental programming concepts like loops, conditionals, and data structures. The for loop approach is simpler, while the while loop provides greater flexibility for game enhancements and user experience improvements.

Updated on: 2026-03-27T15:03:55+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements