School Project, Need Help Fast!
Mike C. Fletcher
mcfletch at rogers.com
Tue Oct 12 18:59:35 EDT 2004
Others have pointed out the need to use quotes around the names and to
use raw_input to get a string, and the desirability of not using huge
if/elif statements, but this is a small note about making it easier on
your users.
Instead of requiring that they capitalize the name, do the work
yourself, it's trivial to implement and avoids a lot of annoying
situations where the user types a name in and gets it wrong merely by
forgetting to capitalize:
mineral = raw_input( "Mineral: " )
mineral = mineral.lower()
# now compare against all-lowercase versions of mineral
Also, consider giving your users information about what minerals are
available (so they don't have to guess), maybe even letting them choose
them from a list that you display (to avoid problems with spelling, I'm
sure *I* would mis-spell Chalcopyrite, for instance).
Oh, and one last idea, this one for making this easier on yourself:
minerals = {}
for line in open( 'mineraltable.csv' ):
name, information = line.split( '\t', 1)
minerals[ name ] = (name, information)
that is, don't store your mineral information in your program, store it
in another file and read it in programmatically. This is a good general
practice, so no reason not to learn it sooner rather than later. The
above code, of course, will only work if you have a single line of text
for each mineral. I'll let you figure out how to make it work for more
than that.
And finally, regarding the project itself, you may find that it's viewed
as being more creative if you make it a simple game... you'll also
likely find it easier if you ask for help earlier, and thus without the
urgency ;) . Oh, and again, as noted by someone else, asking on the
tutors list is a good idea.
Good luck,
Mike
Gavin Bauer wrote:
> Please respond ASAP, the project is due soon.
>
> In science, we are doing a "creative mini project" about minerals.
> People can write a song, or make a movie, etc. etc. Being the dry,
> uncreative person I am, I chose to use my limited python knowledge to
> create a "Mineral Program" the idea is that a person inputs a mineral
> name, and then the program gives them all the information about the
> mineral. At first I figured this would be easy. I would make an input
> line for mineral. Then I would use and if statement, and a whole bunch
> of elif statements, to give the info, here is the broken program I
> came up with:
>
...
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
More information about the Python-list
mailing list