newb ?

C

Chad Everett

Hey guys,

I am back. Trying to expand on a program that was given in the book I am
studying.

No I am not a high school or college student. Doing this on my own. and
having way to much trouble

I am trying to add a hint section to a word jumble program.

I get a traceback error that the word in the jumble is not defined.
Can anyone help?
thanks,

import random

# create a sequence of words to choose from
WORDS = ("python", "easy")
# pick one word randomly from the sequence
word = random.choice(WORDS)
# create a variable to use later to see if the guess is correct
correct = word
# create variable to use for hint if needed
# create a jumbled version of the word
jumble =""
while word:
position = random.randrange(len(word))
jumble += word[position]
word = word[:position] + word[(position + 1):]

# start the game
print \
"""
Welcome to Word Jumble!

Unscramble the letters to make a word.
(Press the enter key at the prompt to quit.)
"""
print "The jumble is:", jumble
print "If you need a hint type 'hint' and Hit enter."

guess = raw_input("\nYour guess: ")
guess = guess.lower()
while (guess != correct) and (guess != "")and (guess != hint): ##not sure
about this either##
print "Sorry, that's not it."
guess = raw_input("Your guess: ")
guess = guess.lower()


###I don"t lnow how to set up this part correct so that when they ask for
the hint it will give it to them###


while word == easy:
if guess == hint:
print "not hard but"
guess = raw_input("Your guess: ")
guess = guess.lower()

while word == python:
if guess == hint:
print "snake"
guess = raw_input("Your guess: ")
guess = guess.lower()

if guess == correct:
print "That's it! You guessed it!\n"

print "Thanks for playing."

raw_input("\n\nPress the enter key to exit.")
 
M

mensanator

Chad said:
Hey guys,

I am back. Trying to expand on a program that was given in the book I am
studying.

No I am not a high school or college student. Doing this on my own. and
having way to much trouble

I am trying to add a hint section to a word jumble program.

I get a traceback error that the word in the jumble is not defined.
Can anyone help?

You have several errors.
thanks,

import random

# create a sequence of words to choose from
WORDS = ("python", "easy")
# pick one word randomly from the sequence
word = random.choice(WORDS)
# create a variable to use later to see if the guess is correct
correct = word
# create variable to use for hint if needed

You didn't create a variable here. Something like

hint = "hint"

And this is the core of your problems. You are confusing a
variable name with the value assigned to it.

# create a jumbled version of the word
jumble =""
while word:
position = random.randrange(len(word))
jumble += word[position]
word = word[:position] + word[(position + 1):]

# start the game
print \
"""
Welcome to Word Jumble!

Unscramble the letters to make a word.
(Press the enter key at the prompt to quit.)
"""
print "The jumble is:", jumble
print "If you need a hint type 'hint' and Hit enter."

Here you have specifically told the user that the hint word is "hint".
guess = raw_input("\nYour guess: ")
guess = guess.lower()
while (guess != correct) and (guess != "")and (guess != hint): ##not sure
about this either##

It will fail because you did not define the hint variable.
Note you actually don't need a hint variable (because the
hint word never changes), you could have said

.... and (guess != "hint")

whereas (guess != correct) needs to compare against a variable
because correct does change.
print "Sorry, that's not it."
guess = raw_input("Your guess: ")
guess = guess.lower()


###I don"t lnow how to set up this part correct so that when they ask for
the hint it will give it to them###


while word == easy:

Same problem here, easy is a variable (which you haven't defined).
What you meant to say was

while word == "easy":

if guess == hint:
print "not hard but"
guess = raw_input("Your guess: ")
guess = guess.lower()

while word == python:

Ditto. But this is going to get tedious when your word list gets large.
You should have your words and their hints stored in a dictionary:

hints = {'easy':'not hard but','python':'snake'}

then you need just a single code block that can print the hint
by using the correct word to look up the hint in the dictionary.

if guess == hint:
print hints[correct]
guess = raw_input("Your guess: ")
guess = guess.lower()
 
C

Chad Everett

Mensanator,

Thanks for your help. That should get me along. I appreciate your time.

Chad
Chad said:
Hey guys,

I am back. Trying to expand on a program that was given in the book I
am
studying.

No I am not a high school or college student. Doing this on my own. and
having way to much trouble

I am trying to add a hint section to a word jumble program.

I get a traceback error that the word in the jumble is not defined.
Can anyone help?

You have several errors.
thanks,

import random

# create a sequence of words to choose from
WORDS = ("python", "easy")
# pick one word randomly from the sequence
word = random.choice(WORDS)
# create a variable to use later to see if the guess is correct
correct = word
# create variable to use for hint if needed

You didn't create a variable here. Something like

hint = "hint"

And this is the core of your problems. You are confusing a
variable name with the value assigned to it.

# create a jumbled version of the word
jumble =""
while word:
position = random.randrange(len(word))
jumble += word[position]
word = word[:position] + word[(position + 1):]

# start the game
print \
"""
Welcome to Word Jumble!

Unscramble the letters to make a word.
(Press the enter key at the prompt to quit.)
"""
print "The jumble is:", jumble
print "If you need a hint type 'hint' and Hit enter."

Here you have specifically told the user that the hint word is "hint".
guess = raw_input("\nYour guess: ")
guess = guess.lower()
while (guess != correct) and (guess != "")and (guess != hint): ##not sure
about this either##

It will fail because you did not define the hint variable.
Note you actually don't need a hint variable (because the
hint word never changes), you could have said

... and (guess != "hint")

whereas (guess != correct) needs to compare against a variable
because correct does change.
print "Sorry, that's not it."
guess = raw_input("Your guess: ")
guess = guess.lower()


###I don"t lnow how to set up this part correct so that when they ask for
the hint it will give it to them###


while word == easy:

Same problem here, easy is a variable (which you haven't defined).
What you meant to say was

while word == "easy":

if guess == hint:
print "not hard but"
guess = raw_input("Your guess: ")
guess = guess.lower()

while word == python:

Ditto. But this is going to get tedious when your word list gets large.
You should have your words and their hints stored in a dictionary:

hints = {'easy':'not hard but','python':'snake'}

then you need just a single code block that can print the hint
by using the correct word to look up the hint in the dictionary.

if guess == hint:
print hints[correct]
guess = raw_input("Your guess: ")
guess = guess.lower()
if guess == correct:
print "That's it! You guessed it!\n"

print "Thanks for playing."

raw_input("\n\nPress the enter key to exit.")
 
S

Steve Holden

Fredrik said:
Chad Everett wrote:




your subject lines still suck. please read this

http://www.catb.org/~esr/faqs/smart-questions.html#bespecific

before you post your next question.

(the entire article is worth reading, if you haven't done so already)
Note also that the subject line on an existing thread can be changed,
though not everyone's software will track the changes, unfortunately.
It's always worth taking the time to make sure the subject line really
does describe the subject of your message - that way people with an
interest in your problem are much more likely to read it instead of
skipping over your posts.

regards
Steve
 
M

Mike Meyer

Steve Holden said:
Note also that the subject line on an existing thread can be changed,
though not everyone's software will track the changes,
unfortunately. It's always worth taking the time to make sure the
subject line really does describe the subject of your message

[Since we're giving posting advice.]

By the same token, don't use a reply to start a new thread. Some
software *will* keep it in the thread, and if they had killed the
thread, they won't see your posts.

<mike
 
G

Grant Edwards

If I can't tell from the subject line what the thread is about, I almost
never read it.
Note also that the subject line on an existing thread can be changed,
though not everyone's software will track the changes, unfortunately. It's
always worth taking the time to make sure the subject line really does
describe the subject of your message

[Since we're giving posting advice.]

By the same token, don't use a reply to start a new thread. Some software
*will* keep it in the thread, and if they had killed the thread, they won't
see your posts.

They don't even have to kill the original thread. By just not expanding the
thread they won't see the "new" thread hidden inside the old one.

This problem seems to be especially prevelent in c.l.p. (as are fractured
threads). I think it's due to people who read the group via an e-mail
gateway (particularly the ones who get the digest service).

Obligatory aside: I'm completely baffled why anybody would choose the
mailing list format over Usenet. I don't even read mailing lists via
mailing lists. I recommend gmane.org's NNTP server for all your mailing
list needs.
 
S

skip

Grant> Obligatory aside: I'm completely baffled why anybody would choose
Grant> the mailing list format over Usenet. I don't even read mailing
Grant> lists via mailing lists. I recommend gmane.org's NNTP server for
Grant> all your mailing list needs.

For the same reason I don't like web forums as a means of communication. I
would much rather operate in an interrupt-driven mode than have to remember
to poll some external service to get my daily helping of information.

Skip
 
G

Grant Edwards


If I allowed news posts to interrupt me, I'd never get anything
done. I limit e-mail to things that really do require fairly
immediate attention.
I notice that a lot of people post here from google.

Ick! Posting to usenet from google. Nasty.
I did it too before I discovered the mailing list, which I now
use because I haven't found a news reader that I like nearly
as much as mutt.

There is an NNTP patch to allow you to use mutt to read Usenet
via an NNTP server.

Mutt users who don't do that seem to like slrn -- it has a very
similar look and feel. One thing significant difference is
slrn's scoring facilities: there's nothing similar in mutt.
It's quite nice to combine email and news into one.

I actually prefer to keep them separate. for me, e-mail is for
stuff that "needs attention", and news is more of a background
thing that I glance through while waiting for a test to finish
or a make to complete.
If you have any suggestions for console-based newsreaders, I'm
all ears.

slrn is the definitive choice -- especially for a mutt user. :)
I have tried to setup "tin" in the past but the voluminosity
of its documentation made me give up.

I used tin for a couple years back in the early 90's, but I
find slrn much more efficient.
 
M

Micah Elliott

Grant> Obligatory aside: I'm completely baffled why anybody would choose
Grant> the mailing list format over Usenet. I don't even read mailing
Grant> lists via mailing lists. I recommend gmane.org's NNTP server for
Grant> all your mailing list needs.

For the same reason I don't like web forums as a means of
communication. I would much rather operate in an interrupt-driven
mode than have to remember to poll some external service to get my
daily helping of information.

Agreed!

I notice that a lot of people post here from google. I did it too
before I discovered the mailing list, which I now use because I
haven't found a news reader that I like nearly as much as mutt. It's
quite nice to combine email and news into one.

If you have any suggestions for console-based newsreaders, I'm all
ears. I have tried to setup "tin" in the past but the voluminosity of
its documentation made me give up.
 
M

Micah Elliott

There is an NNTP patch to allow you to use mutt to read Usenet
via an NNTP server.

Yes, I'm aware of it; it's last (alpha) update was in 1999 and
it probably has some fleas. :)
Mutt users who don't do that seem to like slrn -- it has a very
similar look and feel.

Cool! Thanks for the info. I might give it a try.
 
S

skip

Grant> If I allowed news posts to interrupt me, I'd never get anything
Grant> done. I limit e-mail to things that really do require fairly
Grant> immediate attention.

Well, I do try to limit the number of things I pay attention to. However,
as the "Python guy" at work, participating in this group and the python-dev
mailing list overlap my daytime duties. There are a few other things I
watch as well (matplotlib, pygtk, moin, scipy, etc). Running through all of
them in one place simplifies my life. Last time I checked, most of Usenet
was crap (overrun with spam), so on those few occasions where I need
something I just use Google to search for help and post via Google or Gmane.
I never have to worry about NNTP. I have no idea if my ISP (Comcast) even
provides NNTP access.

Skip
 
M

Mike Meyer

Micah Elliott said:

That's actually how I decide which form I want to use. Mail lists for
thigns I want to interrupt me, newsgroups for things I want to poll.
If you have any suggestions for console-based newsreaders, I'm all
ears. I have tried to setup "tin" in the past but the voluminosity of
its documentation made me give up.

Gnus. Not only will it run in a console, but when run in an X
environment, it'll give you (user-configurable) menu bars, tool bars,
and clickable articles.

<mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top