Make a code for python for a quiz about Present Simple. I want there to be five…
- User
Make a code for python for a quiz about Present Simple. I want there to be five questions, each with 4 answers
- Assistant
import random
questions = [ { "question": "What is the present simple of the verb 'to be'?", "answers": [ "am", "is", "are", "be" ], "correct_answer": "is" }, { "question": "Which of the following is a third person singular present simple verb?", "answers": [ "am", "is", "are", "be" ], "correct_answer": "is" }, { "question": "What is the present simple of the verb 'to eat'?", "answers": [ "ate", "eats", "eating", "eaten" ], "correct_answer": "eats" }, { "question": "What is the present simple of the verb 'to go'?", "answers": [ "went", "going", "goes", "gone" ], "correct_answer": "goes" }, { "question": "Which of the following is a negative sentence in the present simple tense?", "answers": [ "He goes to school every day.", "I like to eat pizza.", "We play basketball on the weekends.", "She doesn't like coffee." ], "correct_answer": "She doesn't like coffee." } ]
- User
Change the quotation marks in your previous answer, the code doesn't compile because of them
- Assistant
Sure! Here's the updated code with the quotation marks changed to single quotes:
import random questions = [ { 'question': 'What is the present simple of the verb "to be"?', 'answers': [ 'am', 'is', 'are', 'be' ], 'correct_answer': 'is' }, { 'question': 'Which of the following is a third person singular present simple verb?', 'answers': [ 'am', 'is', 'are', 'be' ], 'correct_answer': 'is' }, { 'question': 'What is the present simple of the verb "to eat"?', 'answers': [ 'ate', 'eats', 'eating', 'eaten' ], 'correct_answer': 'eats' }, { 'question': 'What is the present simple of the verb "to go"?', 'answers': [ 'went', 'going', 'goes', 'gone' ], 'correct_answer': 'goes' }, { 'question': 'Which of the following is a negative sentence in the present simple tense?', 'answers': [ 'He goes to school every day.', 'I like to eat pizza.', 'We play basketball on the weekends.', 'She doesn\'t like coffee.' ], 'correct_answer': 'She doesn\'t like coffee.' } ] score = 0 for q in random.sample(questions, 5): print(q['question']) random.shuffle(q['answers']) for idx, ans in enumerate(q['answers']): print(f"{idx + 1}. {ans}") user_ans = input("Enter the number of your answer: ") if q['answers'][int(user_ans) - 1] == q['correct_answer']: print("That's correct!") score += 1 else: print("Sorry, that's not correct.") print(f"Your score is {score} out of 5.") - User
Change the quotation marks in your previous answer to ', the code doesn’t compile because of those
- Assistant
Sure, here's the updated code with single quotes:
import random questions = [ { 'question': 'What is the present simple of the verb "to be"?', 'answers': [ 'am', 'is', 'are', 'be' ], 'correct_answer': 'is' }, { 'question': 'Which of the following is a third person singular present simple verb?', 'answers': [ 'am', 'is', 'are', 'be' ], 'correct_answer': 'is' }, { 'question': 'What is the present simple of the verb "to eat"?', 'answers': [ 'ate', 'eats', 'eating', 'eaten' ], 'correct_answer': 'eats' }, { 'question': 'What is the present simple of the verb "to go"?', 'answers': [ 'went', 'going', 'goes', 'gone' ], 'correct_answer': 'goes' }, { 'question': 'Which of the following is a negative sentence in the present simple tense?', 'answers': [ 'He goes to school every day.', 'I like to eat pizza.', 'We play basketball on the weekends.', 'She doesn\'t like coffee.' ], 'correct_answer': 'She doesn\'t like coffee.' } ] score = 0 for q in random.sample(questions, 5): print(q['question']) random.shuffle(q['answers']) for idx, ans in enumerate(q['answers']): print(f"{idx + 1}. {ans}") user_ans = input('Enter the number of your answer: ') if q['answers'][int(user_ans) - 1] == q['correct_answer']: print('That\'s correct!') score += 1 else: print('Sorry, that\'s not correct.') print(f'Your score is {score} out of 5.') - User
Change the quotation marks in your previous answer to U+0060, the code doesn’t compile because of those
- Assistant
Sure, here's the updated code with backticks:
import random questions = [ { `question`: 'What is the present simple of the verb "to be"?', `answers`: [ 'am', 'is', 'are', 'be' ], `correct_answer`: 'is' }, { `question`: 'Which of the following is a third person singular present simple verb?', `answers`: [ 'am', 'is', 'are', 'be' ], `correct_answer`: 'is' }, { `question`: 'What is the present simple of the verb "to eat"?', `answers`: [ 'ate', 'eats', 'eating', 'eaten' ], `correct_answer`: 'eats' }, { `question`: 'What is the present simple of the verb "to go"?', `answers`: [ 'went', 'going', 'goes', 'gone' ], `correct_answer`: 'goes' }, { `question`: 'Which of the following is a negative sentence in the present simple tense?', `answers`: [ 'He goes to school every day.', 'I like to eat pizza.', 'We play basketball on the weekends.', 'She doesn\'t like coffee.' ], `correct_answer`: 'She doesn\'t like coffee.' } ] score = 0 for q in random.sample(questions, 5): print(q[`question`]) random.shuffle(q[`answers`]) for idx, ans in enumerate(q[`answers`]): print(f"{idx + 1}. {ans}") user_ans = input(`Enter the number of your answer: `) if q[`answers`][int(user_ans) - 1] == q[`correct_answer`]: print(`That's correct!`) score += 1 else: print(`Sorry, that's not correct.`) print(f`Your score is {score} out of 5.`)