Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from sys import argv
- def parse(line):
- line_type = "question"
- if line[0:2] == '# ':
- line_type = "heading"
- return (line_type, line)
- if line[0:3] == '## ':
- line_type = "description"
- return (line_type, line)
- # if line[0].isdigit() and line[1] == ')' and line[2] == ' ':
- if line[0].isdigit() and line[1:3] == ') ':
- line_type = "answer"
- line = {
- "number": int(line[0]),
- "line": line[3:]
- }
- return (line_type, line)
- # if line[0] == '-' and line[1] == ' ':
- if line[0:2] == '- ':
- line_type = "right_answer"
- line = line[2:].split(',')
- return (line_type, line)
- script, file_name = argv
- # f = open(file_name)
- # content = f.read()
- # content = content.splitlines()
- content = open(file_name).read().splitlines()
- question_list = []
- current = -1
- for line in content:
- if line == "": continue
- (type_line, line) = parse(line)
- if type_line == "question":
- question_list.append({
- "answers": []
- })
- current = current + 1
- question_list[current]["question"] = line
- if type_line == "answer":
- question_list[current]["answers"].append(line)
- if type_line == "right_answer":
- question_list[current]["right_answer"] = line
- for question in question_list:
- print question
- # Завдання:
- #######
- # Вивести питання за питанням.
- # Після кожного питання вивести варіанти відповіді
- # Після варіантів відповіді, запропонувати користувачу відповісти
- # Вивести на екарн консолі відповідь питання
- #######
- # Слід викориcтовувати конструкцію `for <item> in <item_list>:` (як для питань, так і для варіантів відповіді) та функцію raw_input(">")
- # Для кращого розуміння циклів, можете прочитати цю публікацію: http://jjc.freeshell.org/easytut/Easytut_Russian/node11.html
Advertisement
Add Comment
Please, Sign In to add comment