How to print a line from a text file without a certain character
Question: Not quite sure if this question is a duplicate, but it seems like it isn't,
after searching for a fair while.

Let's say I have these lines of text in text file.

    
    
        Q5) What is 1+1
        A) = 1
        B) = *2
        C) = 0
        D) = -342
        E) = 121
    

The correct answer, `B) = *2`, is written with a `*` mark over the line. How
would you print this line, but without the character, so the line would be
printed like so:

    
    
        Q5) What is 1+1
        A) = 1
        B) = 2
        C) = 0
        D) = -342
        E) = 121
    

I am still new to Python, but I understand that:

    
    
    print lines[3]
    

Would print the specific line. Yet I would like to know how to print a line,
without a certain character.

Any help and explanation on the Coding, will be much appreciated. Thanks Guys.


Answer: EDIT: Given this input:

    
    
    Q1) What is 1*1?
       A) = 0
       B) = *1
       C) = 2
       D) = -1
    Q2) What is 1-1?
       A) = *0
       B) = 1
       C) = 2
       D) = -1
    Q3) What is 1/1?
       A) = 0
       B) = *1
       C) = 2
       D) = -1
    Q4) What is 1%1?
       A) = *0
       B) = 1
       C) = 2
       D) = -1
    Q5) What is 1+1?
       A) = 1
       B) = *2
       C) = 0
       D) = -342
       E) = 121
    

There are many ways to tackle this. These are my first thoughts:

    
    
    import re
    
    def ask_user(answer):
        user_ans = raw_input("> ").strip()
        if user_ans == answer:
            print "Correct!\n"
            result = True
        else:
            print "Wrong!\n"
            result = False
    
        return result
    
    question = None
    
    with open('test.txt') as test:
        for line in test:
            if line[0] == 'Q':
                if question:
                    ask_user(answer)
                question = line
            else:
                m = re.match(r'(.*?)\*(\d+)', line)
                if m:
                    line, answer = m.groups()
                    line = "%s%s\n" % (line,answer)
    
            print line,
    
    # Final question
    ask_user(answer)
    

