Re: [Tutor] Translator - multiple choice answer
Danny and C Smith, Thank you very much for your answers. And sorry for late reply I was away. I will start including encoding=utf8 right away. Printing them with numbers is also great idea and decent compromise, thanks The print function puts a newline at the end. You can change this default behavior by providing an end keyword to it. I'm familiar with end from examples from the internet, but I was not successful with how to implement it into my example... Or something else get merged or I get an error... I will keep try and if I don't succeed I will come back here :-) Thanks for all your help! = This might be useful for reading values from a text value into a dictionary: https://stackoverflow.com/questions/17775273/how-to-read-and-store-values-from-a-text-file-into-a-dictionary-python On Wed, May 14, 2014 at 7:00 PM, Danny Yoo d...@hashcollision.org wrote: 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: pivobeer kruhbread rdeca red krompir potatoe hisahouse cesta road autocar (not even trying to mess with special characters for now, lol) Do look at: http://www.joelonsoftware.com/articles/Unicode.html because the fact that you're dealing with foreign language means you want to get it right. If it were me, I'd just say that the input is UTF-8 encoded text, and always open up the file in utf-8 mode. myfile = open(slo3.txt, r, encoding=utf8) and just know that we're working with Unicode from that point forward. 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? It depends. If you're picking out a random entry, then having a dictionary in hand is not going to need the key lookup support that dictionaries give you. For the application you're describing right now, it doesn't sound like you need this yet. 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. TAB is a reasonable separator. You might also consider comma, as in Comma-Separated Values (CSV). If your data starts having more structure, then check back with folks on the tutor mailing list. There are richer formats you can use, but your program's description suggests that you probably don't need the complexity yet. 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? The print function puts a newline at the end. You can change this default behavior by providing an end keyword to it. The documentation mentions it here: https://docs.python.org/3/library/functions.html#print Small test program to demonstrate: print(Hello , end=) print(world ) 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 How about printing them with numbers, so that entry is just a number rather than the typed word? You can put a graphical user interface on the program, though it does take a bit more effort to get it to work. Look into Tkinter, which is a library for producing graphical user interfaces: https://wiki.python.org/moin/TkInter Another option might be to turn your program into a web site, so that the interface is the web browser, which everyone is getting used to these days. But this, too, is also... involved. :P ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Translator - multiple choice answer
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: pivobeer kruhbread rdeca red krompir potatoe hisahouse cesta road autocar (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... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Translator - multiple choice answer
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: pivobeer kruhbread rdeca red krompir potatoe hisahouse cesta road autocar (not even trying to mess with special characters for now, lol) Do look at: http://www.joelonsoftware.com/articles/Unicode.html because the fact that you're dealing with foreign language means you want to get it right. If it were me, I'd just say that the input is UTF-8 encoded text, and always open up the file in utf-8 mode. myfile = open(slo3.txt, r, encoding=utf8) and just know that we're working with Unicode from that point forward. 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? It depends. If you're picking out a random entry, then having a dictionary in hand is not going to need the key lookup support that dictionaries give you. For the application you're describing right now, it doesn't sound like you need this yet. 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. TAB is a reasonable separator. You might also consider comma, as in Comma-Separated Values (CSV). If your data starts having more structure, then check back with folks on the tutor mailing list. There are richer formats you can use, but your program's description suggests that you probably don't need the complexity yet. 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? The print function puts a newline at the end. You can change this default behavior by providing an end keyword to it. The documentation mentions it here: https://docs.python.org/3/library/functions.html#print Small test program to demonstrate: print(Hello , end=) print(world ) 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 How about printing them with numbers, so that entry is just a number rather than the typed word? You can put a graphical user interface on the program, though it does take a bit more effort to get it to work. Look into Tkinter, which is a library for producing graphical user interfaces: https://wiki.python.org/moin/TkInter Another option might be to turn your program into a web site, so that the interface is the web browser, which everyone is getting used to these days. But this, too, is also... involved. :P ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Translator - multiple choice answer
This might be useful for reading values from a text value into a dictionary: https://stackoverflow.com/questions/17775273/how-to-read-and-store-values-from-a-text-file-into-a-dictionary-python On Wed, May 14, 2014 at 7:00 PM, Danny Yoo d...@hashcollision.org wrote: 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: pivobeer kruhbread rdeca red krompir potatoe hisahouse cesta road autocar (not even trying to mess with special characters for now, lol) Do look at: http://www.joelonsoftware.com/articles/Unicode.html because the fact that you're dealing with foreign language means you want to get it right. If it were me, I'd just say that the input is UTF-8 encoded text, and always open up the file in utf-8 mode. myfile = open(slo3.txt, r, encoding=utf8) and just know that we're working with Unicode from that point forward. 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? It depends. If you're picking out a random entry, then having a dictionary in hand is not going to need the key lookup support that dictionaries give you. For the application you're describing right now, it doesn't sound like you need this yet. 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. TAB is a reasonable separator. You might also consider comma, as in Comma-Separated Values (CSV). If your data starts having more structure, then check back with folks on the tutor mailing list. There are richer formats you can use, but your program's description suggests that you probably don't need the complexity yet. 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? The print function puts a newline at the end. You can change this default behavior by providing an end keyword to it. The documentation mentions it here: https://docs.python.org/3/library/functions.html#print Small test program to demonstrate: print(Hello , end=) print(world ) 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 How about printing them with numbers, so that entry is just a number rather than the typed word? You can put a graphical user interface on the program, though it does take a bit more effort to get it to work. Look into Tkinter, which is a library for producing graphical user interfaces: https://wiki.python.org/moin/TkInter Another option might be to turn your program into a web site, so that the interface is the web browser, which everyone is getting used to these days. But this, too, is also... involved. :P ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor