示例#1
0
def study_chunk(chunk):
    while True:
        talker.print_and_talk("What section would you like to study?")
        selection=simple_menu.ask_list(chunk['section_list'])
        if not selection:
            return
        study_section(chunk,selection)
示例#2
0
def ask_list(items):
    in_choice = True
    while in_choice:
        for i, v in enumerate(items):
            print i, v
        selection = talker.ask("What is your choice? (q to quit)")
        if selection.upper() == 'Q':
            return None
        selection = int(selection)
        if selection < 0 or selection >= len(items):
            talker.print_and_talk("That was not a valid selection.  Please select again.")
        else:
            return items[selection],selection
示例#3
0
def study_section(chunk,selection):
    section = chunk['sections'][selection[0]]
    p_count=len(section['paragraphs'])
    section['points'] = (0, 0)
    if 'studied' not in section:
        section['studied']=(0,p_count)
    print "************************"
    print
    print
    talker.print_and_talk(section['full_title'])
    talker.print_and_talk("You have studied",section['studied'][0],"paragraphs out of",section['studied'][1])

    for i,paragraph in enumerate(section['paragraphs']):
        print
        for line in paragraph:
            talker.print_and_talk(line)
        print
        talker.ask('Hit enter when ready.')
        # for i in range(30):
        #    print '.'
        new_points = study_text(paragraph)
        if new_points is None:
            return
        if i+1>section['studied'][0]:
            section['studied']=(i+1,p_count)
        old_points = section.get('points', (0, 0))
        section['points'] = (old_points[0] + new_points[0], old_points[1] + new_points[1])
        chunk_o_learning.update_chunk(chunk)
示例#4
0
def study_questions(questions, rate):
    if len(questions) < 1:
        return 0, 0
    points = 0
    to_use = max(1, math.trunc(len(questions) * rate))
    total_points = to_use
    if total_points > 1:
        talker.print_and_talk("I will ask " + str(total_points) + " questions.")
    else:
        talker.print_and_talk("I will ask " + str(total_points) + " question.")
    for question in random.sample(questions, to_use):
        talker.print_and_talk_clozure(question['clozure'])
        answer = talker.ask('Fill in the blank:')
        if answer == "I'm done":
            return None
        if answer.lower() == question['word'].lower():
            talker.print_and_talk("You are correct!")
            points += 1
        else:
            talker.print_and_talk("Sorry, I was looking for:", question['word'])
    talker.print_and_talk("You got ", points, "points out of", total_points)
    return points, total_points
示例#5
0
def study_subject(subject):
    talker.print_and_talk("You want to learn about:", subject)
    chunk = fetch_subject_file(subject)
    if not chunk:
        talker.print_and_talk("I will ask wikipedia for the best suggestion")
        suggestion = get_suggestion(subject)
        talker.print_and_talk('"'+suggestion+'"', "was suggested by wikipedia.")
        chunk = fetch_subject_file(suggestion)
        if not chunk:
            article = wikipedia.page(suggestion)
            if not article:
                talker.print_and_talk("Sorry, I couldn't find an article on", suggestion)
                return
            chunk = chunk_o_learning.make_chunk(article,suggestion)
            talker.print_and_talk("I have loaded the article on", suggestion)
        else:
            talker.print_and_talk("I found a local file for", suggestion)
    else:
        talker.print_and_talk("I found a local file for", subject)
    study_chunk(chunk)
示例#6
0
__author__ = 'mrittha'

import talker


def ask_list(items):
    in_choice = True
    while in_choice:
        for i, v in enumerate(items):
            print i, v
        selection = talker.ask("What is your choice? (q to quit)")
        if selection.upper() == 'Q':
            return None
        selection = int(selection)
        if selection < 0 or selection >= len(items):
            talker.print_and_talk("That was not a valid selection.  Please select again.")
        else:
            return items[selection],selection


if __name__ == "__main__":
    selected = ask_list(['item 1', 'item 2', 'item 3'])
    if selected:
        talker.print_and_talk("You chose",selected)