3
3
3DOSES2021-07-18 21:33:32
Python
3DOSES, 2021-07-18 21:33:32

How to answer examples?

The program displays an example and you need to enter the correct answer, but I can’t even figure out how to indicate the correct answer to the examples.

import random
import time

#список
list = ["4+4", "3*4", "3+7", "9-7"]

#вывод рандомного слова 

vivod = random.choice(list)
print(vivod)

#ввод юзером ответ примера и проверка
user = input()
if vivod == user:
    print("Верно")
else:
    print("Ошибка")


Don't pay attention to the time

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-07-18
@3DOSES

Either write it right away normally, through the same dictionary (it will be best), or through literal_eval
1.

questions = {'4+4': 8, '3*4': 12, '3+7': 10, '9-7': 2}

question, answer = random.choice(list(questions.items()))

user = int(input())

if answer == user:
    # ...

2.
from ast import literal_eval

if literal_eval(vivod) == user:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question