K
puts "Мини-викторина. Ответьте на вопросы."
path_question = "./datav/question.txt"
path_answer = "./datav/answer.txt"
def read_txt(path)
if File.exist?(path)
f = File.new(path, "r:UTF-8")
arr = f.readlines
f.close
else
puts "Файл не найден"
end
for i in arr
i.chomp!
end
return arr
end
cnt = 0
answer = nil
questions = read_txt(path_question)
answers = read_txt(path_answer)
cnt = 0
for i in questions
puts i.to_s.chomp
answer = gets.to_s.chomp
if answers.include?(answer)
puts "Верно"
cnt += 1
else
puts "НЕ ВЕРНО"
end
end
puts
puts "Всего вы ответили на #{cnt} ответов из #{questions.size}"