answers = {"She turned ___ the light so as to enjoy the darkness." : "off",
"It was so hot in the room, so she felt she was going to get ___." : "down",
"Mary turned right and came ___ her friend Peter." : "across",
"It will be very cold in the mountains, so put ___ all warm clothes you have." : "on",
"There was no morning when he did not come ___ with a great idea." : "up",
"I can't hear you properly, speak ___, please." : "up",
"Give ___ talking when I start to speak." : "up",
"We get ___ well with our neighbours, we never argue." : "on",
"Be careful, the plane is going to take ___." : "off",
"He was very sad while listening to the teacher who called him ___." : "down"}
print("Fill in the gaps in the sentences.\n")
score = 0
errors = []
for k, v in answers.items():
print(k)
attempt = input("Your answer: ")
if attempt == v:
score = score + 1
else:
errors.append(k)
print("\nYour score is: %i out of 10.\n"%score)
if score < 10:
print("You made mistakes in the following sentences:\n")
for e in errors:
print(e)
Fill in the gaps in the sentences. She turned ___ the light so as to enjoy the darkness. Your answer: off It was so hot in the room, so she felt she was going to get ___. Your answer: down Mary turned right and came ___ her friend Peter. Your answer: across It will be very cold in the mountains, so put ___ all warm clothes you have. Your answer: on There was no morning when he did not come ___ with a great idea. Your answer: up I can't hear you properly, speak ___, please. Your answer: up Give ___ talking when I start to speak. Your answer: up We get ___ well with our neighbours, we never argue. Your answer: up Be careful, the plane is going to take ___. Your answer: up He was very sad while listening to the teacher who called him ___. Your answer: off Your score is: 7 out of 10. You made mistakes in the following sentences: We get ___ well with our neighbours, we never argue. Be careful, the plane is going to take ___. He was very sad while listening to the teacher who called him ___.
exer = ["4^2+3*8", "25+4^3*5", "36^0.5+12",
"34-12*3^2", "2^3+16^0.5-1", "8*0-2^8"]
exer_py = [e.replace('^','**') for e in exer] # заменяем на питоновские ** для степени
answers = [eval(e) for e in exer_py] # исполняем код в кавычках, чтобы сразу получить ответы
with_answers = dict(zip(exer, answers)) # склеиваем вопрос-ответ
for primer, answer in with_answers.items():
print("Решите пример:\n", primer)
attempt = int(input())
while True:
if attempt != answer:
print("Попробуйте еще раз!\n", primer)
attempt = int(input())
else:
print("Верно!")
break
print("Вы решили все примеры! Идите пить чай!")
Решите пример: 4^2+3*8 40 Верно! Решите пример: 25+4^3*5 300 Попробуйте еще раз! 25+4^3*5 345 Верно! Решите пример: 36^0.5+12 18 Верно! Решите пример: 34-12*3^2 -126 Попробуйте еще раз! 34-12*3^2 -74 Верно! Решите пример: 2^3+16^0.5-1 11 Верно! Решите пример: 8*0-2^8 -256 Верно! Вы решили все примеры! Идите пить чай!
Решение выше более общее, то есть, если не знать про eval()
для исполнения кода, заданного в виде строки, можно создать список ответов вручную и потом составить словарь соответствий пример-ответ. Если знать про eval()
, то решение можно упростить и обойтись без словаря соответствий:
exer = ["4^2+3*8", "25+4^3*5", "36^0.5+12",
"34-12*3^2", "2^3+16^0.5-1", "8*0-2^8"]
exer_py = [e.replace('^','**') for e in exer]
for primer in exer_py:
print("Решите пример:\n", primer)
attempt = int(input())
while True:
if attempt != eval(primer):
print("Попробуйте еще раз!\n", primer)
attempt = int(input())
else:
print("Верно!")
break
print("Вы решили все примеры! Идите пить чай!")
# список слов из файла words.txt
word_list = []
with open('words.txt') as f: # or whatever the wordlist is saved as
for line in f.readlines():
word_list.append(line.strip())
word_list
['вышка', 'сессия', 'словарь']
# выбор случайного слова - используйте вторую строчку для выбора слова
from random import choice
rword = choice(word_list)
rword
'вышка'
# i - номер символа, до которого отображаются начальные буквы слова
# (сначала первая, потом первые две, потом перые три и т д)
# n - число пропусков _
i = 1
n = len(rword) - 2
hidden = rword[0:i] + ' _ ' * n + rword[-1]
hidden
'в _ _ _ а'
print("Угадайте слово:", hidden)
attempt = input("Введите слово: ")
while attempt != rword:
i = i + 1 # выводим больше букв
n = n - 1 # и меньше пропусков
hidden = rword[0:i] + ' _ ' * n + rword[-1]
print("Подсказка: ", hidden)
attempt = input("Введите слово: ")
print("Так держать!")
Угадайте слово: в _ _ _ а Введите слово: вилка Подсказка: вы _ _ а Введите слово: вы Подсказка: выш _ а Введите слово: вышка Так держать!