Amazing-Python-Scripts
89 строк · 2.5 Кб
1
2# List of questions for quiz
3
4questions = [5'who is the developer of Python Language',6'when did india gets independence',7'what is the Indian currency',8'Who is World first cloned human baby',9'who is the founder of Hinduism'10]
11
12# list of answers for above questions
13
14answers = [15'Guido Van',16'1947',17'INR',18'Eve',19'No Specific'20]
21
22# List of options for above questions
23
24options = [25['Dennis Ritchie', 'Alan Frank', 'Guido Van', 'Albert'],26['1947', '1995', '1950', '1957'],27['DOLLARS', 'YEN', 'EURO', 'INR'],28['Erik', 'Maria', 'Sophie', 'Eve'],29['Mahavira Swami', 'Mahatma Buddha', 'No Specific', 'Prophet Mohammed']30]
31
32# Quiz Game | Designed by Ishita
33
34# Defining function for game playing
35
36
37def play_game(username, questions, answers, options):38print("Hello,", username, "welcome to the QUIZ game")39print("All the Best for the Game :>")40score = 041for i in range(5):42current_questions = questions[i]43# print(questions[i])44correct_answer = answers[i]45current_question_options = options[i]46print("Questions:", current_questions)47for index, each_options in enumerate(current_question_options):48print(index+1, ") ", each_options, sep='')49user_answer_index = int(input("Please enter your choice(1,2,3,4): "))50user_answer = current_question_options[user_answer_index-1]51if user_answer == correct_answer:52print("correct answer")53score = score + 10054else:55print("wrong answer")56break57print("Your final score is", score)58return username, score59
60# Defining function for viewing the score
61
62
63def view_scores(names_and_scores):64for name, score in names_and_scores.items():65print(name, "has scored", score)66
67# Defining the function for start of the score
68
69
70def quiz(questions, answers, options):71names_and_scores = {}72while True:73print("Welcome to the quiz game")74print("1) Play\n2) View Scores\n3) Exit")75choice = int(input("Please enter your choice: "))76if choice == 1:77username = (input("Please enter your name: "))78username, score = play_game(username, questions, answers, options)79names_and_scores[username] = score80elif choice == 2:81view_scores(names_and_scores)82elif choice == 3:83break84else:85print("Your choice is not correct")86
87# Program execution starts from here
88
89
90quiz(questions, answers, options)91