[Tutor] Translator - multiple choice answer

Mario Py mariopy at gmx.com
Wed May 14 19:30:05 CEST 2014


Hi all, my first post here and my first ever programing project! 
(actually stealing code from all over the internet for now)
So please be easy on me & hints probably will not work with me, I'm 
complete beginner...

I'm trying to create something useful, small program which will help my 
wife to refresh her foreign knowledge of once already memorized words.
Program works. But I would like to expand it a little bit.

Program read TXT file (c:\\slo3.txt)
In this file there are two words per line separated by tab.
First word is foreign language and second word is proper translation, 
like this:

pivo	beer
kruh	bread
rdeca	red
krompir	potatoe
hisa	house
cesta	road
auto	car

(not even trying to mess with special characters for now, lol)

I was going to read content into dictionary, each pair as tuple but I 
gave up, couldn't figure it out. Looks like it is working with the list 
so no problem.

Question 1: would be better to use dictionary, than list?

Question 2: slo3.txt is just small sample for now and before I type in 
all words, I would like to know is it better to use some other separator 
such as coma or empty space instead of TAB? I found on the internet 
example for TAB only, so this is what I'm using for now.

OK here is working code:

from random import shuffle
print('Write translation of Slovene word ')
print()

with open('c:\\slo3.txt') as f:
     lines = f.readlines()

shuffle(lines)

for line in lines:
     question, rightAnswer = line.strip().split('\t') # words are two 
per line separated by TAB.
     answer = input(question + ' ')
     if answer.lower() == rightAnswer:
         a = 0        # please ingore this for now, IF wants something 
here and I don't want to print extra line, output looks OK for now...
         # print()
     else:
         print('Wrong, correct is: %s.' % rightAnswer,)
         print()

I need help with two things. First one is simple, basic, but I couldn't 
figure it out. If I want to print out 'Wrong,,,,' part in the same line 
next to wrong answer, how do I do it?

Now, big, huge help request.
I would like to make it easy on my wife :-) instead of her needing to 
type in answer I would like that she could choose (click on) multiple 
choice. Say she get 4 or 5 possible answers and one of them is correct. 
Then she need to click on correct answer...

What do I need to do? I understand there will be some graphic/windows 
things involved. I don't have any additional packages or libraries 
installed, nor do I know what/how do do it. Complete noob....

I'm using Python 3.4 and Windows 7.

Mario

P.s.
I'm not even sure if this will show up on Tutor's forum...


More information about the Tutor mailing list