Amazing-Python-Scripts

Форк
0
89 строк · 2.5 Кб
1

2
# List of questions for quiz
3

4
questions = [
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

14
answers = [
15
    'Guido Van',
16
    '1947',
17
    'INR',
18
    'Eve',
19
    'No Specific'
20
]
21

22
#  List of options for above questions
23

24
options = [
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

37
def play_game(username, questions, answers, options):
38
    print("Hello,", username, "welcome to the QUIZ game")
39
    print("All the Best for the Game :>")
40
    score = 0
41
    for i in range(5):
42
        current_questions = questions[i]
43
        # print(questions[i])
44
        correct_answer = answers[i]
45
        current_question_options = options[i]
46
        print("Questions:", current_questions)
47
        for index, each_options in enumerate(current_question_options):
48
            print(index+1, ") ", each_options, sep='')
49
        user_answer_index = int(input("Please enter your choice(1,2,3,4): "))
50
        user_answer = current_question_options[user_answer_index-1]
51
        if user_answer == correct_answer:
52
            print("correct answer")
53
            score = score + 100
54
        else:
55
            print("wrong answer")
56
            break
57
    print("Your final score is", score)
58
    return username, score
59

60
# Defining function for viewing the score
61

62

63
def view_scores(names_and_scores):
64
    for name, score in names_and_scores.items():
65
        print(name, "has scored", score)
66

67
# Defining the function for start of the score
68

69

70
def quiz(questions, answers, options):
71
    names_and_scores = {}
72
    while True:
73
        print("Welcome to the quiz game")
74
        print("1) Play\n2) View Scores\n3) Exit")
75
        choice = int(input("Please enter your choice: "))
76
        if choice == 1:
77
            username = (input("Please enter your name: "))
78
            username, score = play_game(username, questions, answers, options)
79
            names_and_scores[username] = score
80
        elif choice == 2:
81
            view_scores(names_and_scores)
82
        elif choice == 3:
83
            break
84
        else:
85
            print("Your choice is not correct")
86

87
#  Program execution starts from here
88

89

90
quiz(questions, answers, options)
91

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.