1,105,633 Community Members

Word Jumble python program

Member Avatar
dseto200
Junior Poster in Training
56 posts since Nov 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Listed below is the original word jumble python program.
According to the exercise i'm supposed to add hints see next thread on my modified program however it doesn't work correctly.

# Word Jumble
# 
# The computer picks a random word then "jumbles" it
# The player has to guess the original word
#  
import random
 
# create a sequence of words to choose from
WORDS = ("python", "jumble", "easy", "difficult", "answer", "xylophone")          
  
#  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 a jumbled version of the word
jumble =""
 
while word:
  position = random.randrange(len(word))
  jumble += word[position]
  word = word[:position] + word[(position + 1):]
  
# sets score to zero
score = 0
 
# start the game
print \
   """
              Welcome to Word Jumble!
 
 Unscramble the letters to make a word.
 Enter a guess, an X to give up, or type ? and press enter for a hint.
 (Press the enter key at the prompt to quit.)
 
 Try to get the lowest score possible. For each hint, you gain a point.
 See if you can win with no points!
 """
print "The jumble is:", jumble

guess = raw_input("\nYour guess: ")
guess = guess.lower()
lst = range(len(jumble))
hint_str = '_'*len(jumble)
while True:
 
     
 if guess == correct:
      print "That's it! You guessed it!\n Your score is", score
      raw_input("\n\nPress the enter key to exit.")
      break
      guess = raw_input("Guess or '?' or 'X': ").lower()

 elif guess == '?':
       i = random.choice(lst)
       print correct[i], "is the", i+1, "letter."
       score += 1
       guess = raw_input("Guess or '?' or 'X': ").lower()
       
       
 elif guess == 'x':
       print "Sorry you gave up!"
       break
 else:
       print "Sorry, thats not it. Try again."
       guess = raw_input("Guess or '?' or 'X': ").lower()
Member Avatar
dseto200
Junior Poster in Training
56 posts since Nov 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Now it works now. Ahhh.
Weird it wasn't working now after I put this solution in this thread now it works.
Only problem sometime that dumb random function will return
the same hint "i.e b is the letter4" two times in a row.

# Word Jumble
# 
# The computer picks a random word then "jumbles" it
# The player has to guess the original word
#  
import random
 
# create a sequence of words to choose from
WORDS = ("python", "jumble", "easy", "difficult", "answer", "xylophone")          
  
#  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 a jumbled version of the word
jumble =""
 
while word:
  position = random.randrange(len(word))
  jumble += word[position]
  word = word[:position] + word[(position + 1):]
  
# sets score to zero
score = 0
 
# start the game
print \
   """
              Welcome to Word Jumble!
 
 Unscramble the letters to make a word.
 Enter a guess, an X to give up, or type ? and press enter for a hint.
 (Press the enter key at the prompt to quit.)
 
 Try to get the lowest score possible. For each hint, you gain a point.
 See if you can win with no points!
 """
print "The jumble is:", jumble

guess = raw_input("\nYour guess: ")
guess = guess.lower()
lst = range(len(jumble))
hint_str = '_'*len(jumble)
while True:
 
     
 if guess == correct:
      print "That's it! You guessed it!\n Your score is", score
      raw_input("\n\nPress the enter key to exit.")
      break
      guess = raw_input("Guess or '?' or 'X': ").lower()

 elif guess == '?':
       i = random.choice(lst)
       print correct[i], "is the", i+1, "letter."
       score += 1
       guess = raw_input("Guess or '?' or 'X': ").lower()
       
       
 elif guess == 'x':
       print "Sorry you gave up!"
       break
 else:
       print "Sorry, thats not it. Try again."
       guess = raw_input("Guess or '?' or 'X': ").lower()
Member Avatar
Freaky_Chris
Master Poster
702 posts since Apr 2008
Reputation Points: 299 [?]
Q&As Helped to Solve: 119 [?]
Skill Endorsements: 0 [?]
 
-1
 

create a list of which characters have been hinted and check the new hint doesn't match any of the previous.

You can also limit people to X amounts of hints too

Chris

Member Avatar
ksekwamote
Newbie Poster
4 posts since Oct 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

u did not continue it this code

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
0
 
Question Answered as of 5 Months Ago by vegaseat, Freaky_Chris and ksekwamote
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article