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()
bdtask commented: Thanks for shearing your helpful information article +0

Recommended Answers

All 5 Replies

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()

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

u did not continue it this code

# Python program for jumbled words game. 

# import random module 
import random 

# function for choosing random word. 
def choose(): 
    # list of word 
    words = ['rainbow', 'computer', 'science', 'programming', 
            'mathematics', 'player', 'condition', 'reverse', 
            'water', 'board', 'geeks'] 

    # choice() method randomly choose 
    # any word from the list. 
    pick = random.choice(words) 

    return pick 

# Function for shuffling the 
# characters of the chosen word. 
def jumble(word): 
    # sample() method shuffling the characters of the word 
    random_word = random.sample(word, len(word)) 

    # join() method join the elements 
    # of the iterator(e.g. list) with particular character . 
    jumbled = ''.join(random_word) 
    return jumbled 

# Function for showing final score. 
def thank(p1n, p2n, p1, p2): 
    print(p1n, 'Your score is :', p1) 
    print(p2n, 'Your score is :', p2) 

    # check_win() function calling 
    check_win(p1n, p2n, p1, p2) 

    print('Thanks for playing...') 

# Function for declaring winner 
def check_win(player1, player2, p1score, p2score): 
    if p1score > p2score: 
        print("winner is :", player1) 
    elif p2score > p1score: 
        print("winner is :", player2) 
    else: 
        print("Draw..Well Played guys..") 

# Function for playing the game. 
def play(): 
    # enter player1 and player2 name 
    p1name = input("player 1, Please enter your name :") 
    p2name = input("Player 2 , Please enter your name: ") 

    # variable for counting score. 
    pp1 = 0
    pp2 = 0

    # variable for counting turn 
    turn = 0

    # keep looping 
    while True: 

        # choose() function calling 
        picked_word = choose() 

        # jumble() fucntion calling 
        qn = jumble(picked_word) 
        print("jumbled word is :", qn) 

        # checking turn is odd or even 
        if turn % 2 == 0: 

            # if turn no. is even 
            # player1 turn 
            print(p1name, 'Your Turn.') 

            ans = input("what is in your mind? ") 

            # checking ans is equal to picked_word or not 
            if ans == picked_word: 

                # incremented by 1 
                pp1 += 1

                print('Your score is :', pp1) 
                turn += 1

            else: 
                print("Better luck next time ..") 

                # player 2 turn 
                print(p2name, 'Your turn.') 

                ans = input('what is in your mind? ') 

                if ans == picked_word: 
                    pp2 += 1
                    print("Your Score is :", pp2) 

                else: 
                    print("Better luck next time...correct word is :", picked_word) 

                c = int(input("press 1 to continue and 0 to quit :")) 

                # checking the c is equal to 0 or not 
                # if c is equal to 0 then break out 
                # of the while loop o/w keep looping. 
                if c == 0: 
                    # thank() function calling 
                    thank(p1name, p2name, pp1, pp2) 
                    break

        else: 

            # if turn no. is odd 
            # player2 turn 
            print(p2name, 'Your turn.') 
            ans = input('what is in your mind? ') 

            if ans == picked_word: 
                pp2 += 1
                print("Your Score is :", pp2) 
                turn += 1

            else: 
                print("Better luck next time.. :") 
                print(p1name, 'Your turn.') 
                ans = input('what is in your mind? ') 

                if ans == picked_word: 
                    pp1 += 1
                    print("Your Score is :", pp1) 

                else: 
                    print("Better luck next time...correct word is :", picked_word) 

                    c = int(input("press 1 to continue and 0 to quit :")) 

                    if c == 0: 
                        # thank() function calling 
                        thank(p1name, p2name, pp1, pp2) 
                        break

            c = int(input("press 1 to continue and 0 to quit :")) 
            if c == 0: 
                # thank() function calling 
                thank(p1name, p2name, pp1, pp2) 
                break

# Driver code 
if __name__ == '__main__': 

    # play() function calling 
    play() 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.