Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- current_path = File.dirname(__FILE__)
- question = current_path + "/questions.txt"
- answer = current_path + "/answers.txt"
- if File.exist?(question)
- f = File.new(question, "r:UTF-8")
- questions = f.readlines
- f.close
- else
- puts "Файл с вопросами не найден"
- end
- if File.exist?(answer)
- f = File.new(answer, "r:UTF-8")
- answers = f.readlines
- f.close
- else
- puts "Файл с ответами не найден"
- end
- for item in answers do
- item.gsub(/[^0-9.,]/, "")
- end
- n = 0
- right = 0
- while n <= questions.size
- puts questions[n]
- user_input = STDIN.gets.chomp
- if user_input.to_i == answers[n].to_i
- puts "Верный ответ"
- right += 1
- else
- puts "Неправильный ответ. Правильный ответ: #{answers[n]}"
- end
- n += 1
- puts
- end
- puts "Вы ответили правильно на #{right.to_s} вопросов из #{questions.size}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement