154k views
1 vote
Can anyone please write this python code with four easy python theory MCQ questions

Can anyone please write this python code with four easy python theory MCQ questions-example-1

1 Answer

5 votes

You can add more questions to the array of questions. I made explanations where necessary. It was a dynamic program. It is compatible not for a single question but for many questions. Good luck. Do not hesitate to contact me if you have any problems.

#Question displayer

def showQuestion(questions, choices, answer):

for i, (question, options) in enumerate(questions.items(), start=1):

print(f"Question {i}: {question}")

for idx, option in options.items():

print(f"{idx}) {option}")

user_answer = input("Write your option(a/b/c/d): ")

if user_answer in options and options[user_answer] == answer[i-1]:

print("Correct answer! Good keep it up!\\")

else:

print(f"Wrong. Correct answer: {answer[i-1]}\\")

#Question List

questions = {

"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"

},

"Example question?": {

"A": "Wrong answer",

"B": "Not an answer",

"C": "This is the answer",

"D": "C is the answer"

}

#... and so on. You can add your question(s).

}

choices, answers = ["A", "C"], ["Indentation", "This is the answer"]

def Main():

showQuestion(questions, choices, answers)

if(__name__ == "__main__"):

Main()

Can anyone please write this python code with four easy python theory MCQ questions-example-1
Can anyone please write this python code with four easy python theory MCQ questions-example-2
User GrigorisG
by
7.6k points

No related questions found