Kaun Banega Crorepati Simaulation using Python

Nov. 23, 2023, 3:12 p.m.


...

KBC
1. Questions with options
2. Take home money
3. Threshold value of money
4. Display correct answer in case of user quit or wrong answer.
5. Ask for options again if answer format is not correct.

KBC
1. Questions with options
2. Take home money
3. Threshold value of money
4. Display correct answer in case of user quit or wrong answer.
5. Ask for options again if answer format is not correct.

set_of_ques=[
    [
        '1. Who developed Python Programming Language?',
        'a) Wick van Rossum',
        'b) Rasmus Lerdorf',
        'c) Guido van Rossum',
        'd) Niene Stom',
        3
        
    ],
    [
       '2. Which type of Programming does Python support?',
        'a) object-oriented programming',
        'b) structured programming',
        'c) functional programming',
        'd) all of the mentioned',
        4
    ],
     [
        '3. Which of the following is used to define a block of code in Python language?',
         'a) Indentation',
         'b) Key',
         'c) Brackets',
         'd) All of the mentioned',
         1
        
    ],
     [
        '4. Python supports the creation of anonymous functions at runtime, using a construct called',
         'a) pi',
         'b) anonymous',
         'c) lambda',
         'd) def',
         3
        
    ],
     [
        '5. What does pip stand for python?',
         'a) Pip Installs Python',
         'b) Pip Installs Packages',
         'c) Preferred Installer Program',
         'd) All of the mentioned',
         3
        
    ],
    [
        '6. Who developed Python Programming Language?',
        'a) Wick van Rossum',
        'b) Rasmus Lerdorf',
        'c) Guido van Rossum',
        'd) Niene Stom',
        3
        
    ],
    [
       '7. Which type of Programming does Python support?',
        'a) object-oriented programming',
        'b) structured programming',
        'c) functional programming',
        'd) all of the mentioned',
        4
    ],
     [
        '8. Which of the following is used to define a block of code in Python language?',
         'a) Indentation',
         'b) Key',
         'c) Brackets',
         'd) All of the mentioned',
         1
        
    ],
     [
        '9. Python supports the creation of anonymous functions at runtime, using a construct called',
         'a) pi',
         'b) anonymous',
         'c) lambda',
         'd) def',
         3
        
    ],
     [
        '10. What does pip stand for python?',
         'a) Pip Installs Python',
         'b) Pip Installs Packages',
         'c) Preferred Installer Program',
         'd) All of the mentioned',
         3
        
    ],
        [
        '11. Who developed Python Programming Language?',
        'a) Wick van Rossum',
        'b) Rasmus Lerdorf',
        'c) Guido van Rossum',
        'd) Niene Stom',
        3
        
    ],
    [
       '12. Which type of Programming does Python support?',
        'a) object-oriented programming',
        'b) structured programming',
        'c) functional programming',
        'd) all of the mentioned',
        4
    ],
     [
        '13. Which of the following is used to define a block of code in Python language?',
         'a) Indentation',
         'b) Key',
         'c) Brackets',
         'd) All of the mentioned',
         1
        
    ],
     [
        '14. Python supports the creation of anonymous functions at runtime, using a construct called',
         'a) pi',
         'b) anonymous',
         'c) lambda',
         'd) def',
         3
        
    ],
     [
        '15. What does pip stand for python?',
         'a) Pip Installs Python',
         'b) Pip Installs Packages',
         'c) Preferred Installer Program',
         'd) All of the mentioned',
         3
        
    ]   
]
# Payout Structure based on no of questions answered correctly.
level=[1000,2000,3000,5000,10000,20000,40000,80000,160000,320000,640000,1250000,2500000,5000000,10000000]

# Threshold value after answering some specific no of questions.
take_home = 0

for i in range(len(set_of_ques)):
    print(f"\n{set_of_ques[i][0]}") # To print the questions
    
    for j in range(1,len(set_of_ques[i])-1):
        print(f'\t{set_of_ques[i][j]}') # To print the options
       
    dict1 = {'a':1,'b':2,'c':3,'d':4,'q':'quit'} # Mapping of options to index value
    
    # Loop to get the correct answer. Ask for options again if the answer format is not correct.
    while(True):
        answer = input("Enter your answer(a-d) or q to quit: ")  # Asking for answers
        answer= answer.lower() # To change the answer in lowercase.
        
        # if answer value is not present in key then answer is not in correct format.
        if answer not in dict1.keys(): 
            print("Please choose from a, b, c, d and q to quit:")
            continue # To go to loop and ask for answer again
        else:
            break # to break the loop if the answer is in correct format.

    # To implement if someone quit in between.
    if answer == 'q':
        print(f"You take home money is {take_home}")
        break
        
    if dict1[answer] == set_of_ques[i][5]:
        print(f'Correct answer. You have won for Rs.{level[i]}')
        if i==4:
            take_home=level[i]
            print(f"You take home money is Rs. {take_home}")
        elif i==9:
            take_home=level[i]
            print(f"You take home money is Rs. {take_home}")
        elif i==14:
            take_home=level[i]
            print(f"You take home money is Rs. {take_home}")
            break
            
    else:
        print('Wrong answer')
        print(f'The correct answer is "{set_of_ques[i][set_of_ques[i][5]]}"')

        if i>4:
            print(f"You take home money is Rs. {take_home}")
        else:
            print(f"\nSorry! Try again.")
        break
1. Who developed Python Programming Language?
	a) Wick van Rossum
	b) Rasmus Lerdorf
	c) Guido van Rossum
	d) Niene Stom
Enter your answer(a-d) or q to quit:  c
Correct answer. You have won for Rs.1000

2. Which type of Programming does Python support?
	a) object-oriented programming
	b) structured programming
	c) functional programming
	d) all of the mentioned
Enter your answer(a-d) or q to quit:  d
Correct answer. You have won for Rs.2000

3. Which of the following is used to define a block of code in Python language?
	a) Indentation
	b) Key
	c) Brackets
	d) All of the mentioned
Enter your answer(a-d) or q to quit:  a
Correct answer. You have won for Rs.3000

4. Python supports the creation of anonymous functions at runtime, using a construct called
	a) pi
	b) anonymous
	c) lambda
	d) def
Enter your answer(a-d) or q to quit:  c
Correct answer. You have won for Rs.5000

5. What does pip stand for python?
	a) Pip Installs Python
	b) Pip Installs Packages
	c) Preferred Installer Program
	d) All of the mentioned
Enter your answer(a-d) or q to quit:  c
Correct answer. You have won for Rs.10000
You take home money is Rs. 10000

6. Who developed Python Programming Language?
	a) Wick van Rossum
	b) Rasmus Lerdorf
	c) Guido van Rossum
	d) Niene Stom
Enter your answer(a-d) or q to quit:  c
Correct answer. You have won for Rs.20000

7. Which type of Programming does Python support?
	a) object-oriented programming
	b) structured programming
	c) functional programming
	d) all of the mentioned
Enter your answer(a-d) or q to quit:  d
Correct answer. You have won for Rs.40000

8. Which of the following is used to define a block of code in Python language?
	a) Indentation
	b) Key
	c) Brackets
	d) All of the mentioned
Enter your answer(a-d) or q to quit:  a
Correct answer. You have won for Rs.80000

9. Python supports the creation of anonymous functions at runtime, using a construct called
	a) pi
	b) anonymous
	c) lambda
	d) def
Enter your answer(a-d) or q to quit:  c
Correct answer. You have won for Rs.160000

10. What does pip stand for python?
	a) Pip Installs Python
	b) Pip Installs Packages
	c) Preferred Installer Program
	d) All of the mentioned
Enter your answer(a-d) or q to quit:  c
Correct answer. You have won for Rs.320000
You take home money is Rs. 320000

11. Who developed Python Programming Language?
	a) Wick van Rossum
	b) Rasmus Lerdorf
	c) Guido van Rossum
	d) Niene Stom
Enter your answer(a-d) or q to quit:  c
Correct answer. You have won for Rs.640000

12. Which type of Programming does Python support?
	a) object-oriented programming
	b) structured programming
	c) functional programming
	d) all of the mentioned
Enter your answer(a-d) or q to quit:  d
Correct answer. You have won for Rs.1250000

13. Which of the following is used to define a block of code in Python language?
	a) Indentation
	b) Key
	c) Brackets
	d) All of the mentioned
Enter your answer(a-d) or q to quit:  a
Correct answer. You have won for Rs.2500000

14. Python supports the creation of anonymous functions at runtime, using a construct called
	a) pi
	b) anonymous
	c) lambda
	d) def
Enter your answer(a-d) or q to quit:  c
Correct answer. You have won for Rs.5000000

15. What does pip stand for python?
	a) Pip Installs Python
	b) Pip Installs Packages
	c) Preferred Installer Program
	d) All of the mentioned
Enter your answer(a-d) or q to quit:  c
Correct answer. You have won for Rs.10000000
You take home money is Rs. 10000000




Tags


Downloads

KBC Notebook

Comments