making a small, simple Python script to help memorize things

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Jave D
chavey-dee
Posts: 1042
Joined: Mon Oct 18, 2010 4:41 pm UTC

making a small, simple Python script to help memorize things

Postby Jave D » Tue Oct 15, 2013 10:47 pm UTC

Hi.

So I haven't really ever learned how to program, and I'm not really looking to learn. I know *some* Python (functional based mostly, haven't ever used classes right nor do I see a need to now), have a lot of notes and examples on it. But what I'm trying to do is memorize a bunch of UPC codes for various products at work and I'd like to whip up a small non-GUI based python app to do this since for some reason this seems like more fun then trying to use index cards. (There are a lot of these codes.)

I guess what I'm asking is if someone could point me in the right direction i.e. where to start. The UPC codes are numerical strings assigned to specific products and what I'd like for the program to wind up doing is just 'quiz' me, giving me a random product name and asking me to enter in the correct UPC code. But I'm not sure what data type is best for the codes (there are a lot of products, a couple hundred). Any help is appreciated!

User avatar
skeptical scientist
closed-minded spiritualist
Posts: 6142
Joined: Tue Nov 28, 2006 6:09 am UTC
Location: San Francisco

Re: making a small, simple Python script to help memorize th

Postby skeptical scientist » Wed Oct 16, 2013 1:33 am UTC

I'd use a dictionary to map UPC codes to product names. You could map in the reverse direction as well, but it seems cleaner to have the keys in a standardized format rather than the values.
I'm looking forward to the day when the SNES emulator on my computer works by emulating the elementary particles in an actual, physical box with Nintendo stamped on the side.

"With math, all things are possible." —Rebecca Watson

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: making a small, simple Python script to help memorize th

Postby ahammel » Wed Oct 16, 2013 3:44 am UTC

The UPCs should probably be strings. There's a temptation to use a numerical data type for strings of digits (phone numbers, for instance) but that's usually wrong: you'll probably want to do string things like printing and counting the number of digits, not int things like math.

Mapping UPCs to product codes using a dict is the approach I'd take, at least at this level of complexity. When you're actually running the quiz, you'll be treating it more like a list (I think you have to to select a random key/value pair in python), but the dict has the advantage of guaranteeing that a UPC identifies no more than one product.

What's the input format? How does the program know what UPC identifies what product?
He/Him/His/Alex
God damn these electric sex pants!

User avatar
Jave D
chavey-dee
Posts: 1042
Joined: Mon Oct 18, 2010 4:41 pm UTC

Re: making a small, simple Python script to help memorize th

Postby Jave D » Wed Oct 16, 2013 4:46 am UTC

ahammel wrote:The UPCs should probably be strings. There's a temptation to use a numerical data type for strings of digits (phone numbers, for instance) but that's usually wrong: you'll probably want to do string things like printing and counting the number of digits, not int things like math.

Mapping UPCs to product codes using a dict is the approach I'd take, at least at this level of complexity. When you're actually running the quiz, you'll be treating it more like a list (I think you have to to select a random key/value pair in python), but the dict has the advantage of guaranteeing that a UPC identifies no more than one product.

What's the input format? How does the program know what UPC identifies what product?


The input format would just be raw text, and as for how the program knows what UPC goes with what product, well that's sort of what I'm trying to figure out. :)

jareds
Posts: 436
Joined: Wed Jan 03, 2007 3:56 pm UTC

Re: making a small, simple Python script to help memorize th

Postby jareds » Wed Oct 16, 2013 7:00 am UTC

This isn't a coding answer, but since you said you're not looking to learn programming you may just want an existing solution: "BSD games" is a collection of classic UNIX text games. It includes the program "quiz", which can quiz you on anything you want if you provide your own input file. I used it to memorize foreign language vocab in college. "BSD games" should be available as either "bsdgames" or "bsd-games" on pretty much every Linux or BSD distribution ever, or in Cygwin on Windows. Cygwin is a system that provides a Unix-like environment on Windows that sucks for many purposes but would be fine for running "quiz". Or you could search "bsdgames source" and try and build from source natively on Windows, but you might find that trickier. But really there are probably many free programs that do a simple quiz from a question/answer file, so this is a slightly odd thing to do if you're not looking to program at some level.

troyp
Posts: 557
Joined: Thu May 22, 2008 9:20 pm UTC
Location: Lismore, NSW

Re: making a small, simple Python script to help memorize th

Postby troyp » Wed Oct 16, 2013 11:07 pm UTC

There are heaps of "quiz" type programs, most of them GUI, with all sorts of features. Just search for "quiz app", "flash card app" and variants.

If you use Python, you'd represent the questions as either a dictionary:

Code: Select all

quiz_questions = { 'q1': 'a1', 'q2': 'a2',
                   'q3': 'a3', 'q4': 'a4' }

or a list:

Code: Select all

quiz_questions = [ ('q1', 'a1'), ('q2', 'a2'),
                   ('q3', 'a3'), ('q4', 'a4') ]


You'd then use the random module to choose questions randomly (eg. a random.choice() inside a loop to choose "with replacement", or random.sample() to choose a list of questions without replacement, then iterate through them.).

User avatar
PM 2Ring
Posts: 3715
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: making a small, simple Python script to help memorize th

Postby PM 2Ring » Thu Oct 17, 2013 7:11 am UTC

I agree with the suggestions to use a dict, although a list of tuples is probably adequate for this program. Note that the dict() function can be used to turn a list of tuples into a dict.

Do you have access to an existing digital list of UPC numbers & product names, or will you need to create it yourself from scratch?

You probably don't want to hard-code the questions & answers into the program. Instead, your program should read them from a simple text file and build the dict when it starts up. I suggest putting one product per line:
UPCNumber Product Name String

If you want to get fancy, your dict creation function could allow blank lines and even comments in the text file. And you might want to use a more robust record format, eg have an explicit field separator, so that it can be used for other quizzes where the answers aren't restricted to being just a single word.

What version of Python are you using? Will you be running it on Windows or *nix?
There's a module called readline which is standard on *nix Python installations that makes reading from the console a bit nicer. You just have to import readline and then when you ask for user input using input() or raw_input() the user automatically gets line editing.

Another thing you might consider is to make the quiz multiple choice. OTOH, I guess having to type in the UPC numbers all the time will help you to memorize them.

Once you get this program working, you may want to create an enhanced version that keeps track of your performance, so that the program assigns a higher probability of selection to codes that you get wrong, although that does make the random selection routine a little more complicated.

User avatar
Jave D
chavey-dee
Posts: 1042
Joined: Mon Oct 18, 2010 4:41 pm UTC

Re: making a small, simple Python script to help memorize th

Postby Jave D » Sat Oct 26, 2013 4:51 am UTC

That advanced routine does sound interesting, but a beyond what is strictly speaking necessary. What I've got so far works for what I need it to do.

Thanks for the help guys! 8-)

D-503
Posts: 84
Joined: Sun Apr 15, 2012 11:35 pm UTC

Re: making a small, simple Python script to help memorize th

Postby D-503 » Sat Nov 02, 2013 7:47 am UTC

If you're interested in hearing about more memorization software, I highly recommend Anki. Flashcards can contain images of the products you want to memorize, it uses spaced-repetition, you can import data from spreadsheets, you can use it on multiple platforms and sync your flashcards across them and has a lot of cool features for doing other stuff.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 6 guests