Hi All,
I am new in learning programming. I am very lost. I read all of the chapters over and over again and I am still lost. I have the program below that I need to modify it to add hint to it when the user couldn't figure out the jumble word. Somehow the program didn't run. Can someone please look at it and enlighten me to see what I am missing? Is there any advise in learning and improving my programming skill? I am very disappointed at myself right now. It seems like I am from earth and programming language is from venus. I don't understand anything. Please help.
# Word Jumble
#
# The computer picks a random word and 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):]
# 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
guess = raw_input("\nYour guess: ")
guess = guess.lower()
hint = "hint"
while (guess != correct) and (guess != "")and (guess =="hint"):
print "Sorry, that's not it. Would you like a hint?"
guess = raw_input("Your guess: ")
guess = guess.lower()
if guess ==hint and word =="easy":
print "not hard but"
guess = raw_input("Your guess: ")
guess = guess.lower()
elif guess ==hint and word =="python":
print "snake"
guess = raw_input("Your guess: ")
guess = guess.lower()
elif guess ==hint and word =="jumble":
print "shuffle"
guess = raw_input("Your guess: ")
guess = guess.lower()
elif guess ==hint and word =="difficult":
print "complicated"
guess = raw_input("Your guess: ")
guess = guess.lower()
elif guess ==hint and word =="answer":
print "solution"
guess = raw_input("Your guess: ")
guess = guess.lower()
else:
print "Musical instrument that consists of bars of various lengths."
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.")
3 1949
Will you post this again? Only this time, look to the right of the message box and read the posting guidelines - the item that say "Use CODE tags" so that the structure of your code comes through. This way it's easy to copy and test your post.
Hi All,
I am new in learning programming. I am very lost. I read all of the chapters over and over again and I am still lost. I have the program below that I need to modify it to add hint to it when the user couldn't figure out the jumble word. Somehow the program didn't run. Can someone please look at it and enlighten me to see what I am missing? Is there any advise in learning and improving my programming skill? I am very disappointed at myself right now. It seems like I am from earth and programming language is from venus. I don't understand anything. Please help.
# Word Jumble
#
# The computer picks a random word and 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):]
# 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
guess = raw_input("\nYour guess: ")
guess = guess.lower()
hint = "hint"
while (guess != correct) and (guess != "")and (guess =="hint"):
print "Sorry, that's not it. Would you like a hint?"
guess = raw_input("Your guess: ")
guess = guess.lower()
if guess ==hint and word =="easy":
print "not hard but"
guess = raw_input("Your guess: ")
guess = guess.lower()
elif guess ==hint and word =="python":
print "snake"
guess = raw_input("Your guess: ")
guess = guess.lower()
elif guess ==hint and word =="jumble":
print "shuffle"
guess = raw_input("Your guess: ")
guess = guess.lower()
elif guess ==hint and word =="difficult":
print "complicated"
guess = raw_input("Your guess: ")
guess = guess.lower()
elif guess ==hint and word =="answer":
print "solution"
guess = raw_input("Your guess: ")
guess = guess.lower()
else:
print "Musical instrument that consists of bars of various lengths."
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.")
I noticed an odd char in one line maybe a char missing or some such with a smiley face. don't know how much that helps though
word = word[osition] + word[(position + 1):]
(The odd character is just the two characters :p being interpreted as the :p emoticon because the code wasn't posted inside of code tags.)
The if- elif chain in your main loop is indented too far. You probably want something like - while ( (guess != correct) and (guess != "") ) or (guess =="hint"):
-
print "Sorry, that's not it. Would you like a hint?"
-
guess = raw_input("Your guess: ")
-
guess = guess.lower()
-
if guess ==hint and word =="easy":
-
print "not hard but"
-
guess = raw_input("Your guess: ")
-
guess = guess.lower()
-
-
elif guess ==hint and word =="python":
-
print "snake"
-
guess = raw_input("Your guess: ")
-
guess = guess.lower()
-
-
elif guess ==hint and word =="jumble":
-
print "shuffle"
-
guess = raw_input("Your guess: ")
-
guess = guess.lower()
-
-
elif guess ==hint and word =="difficult":
-
print "complicated"
-
guess = raw_input("Your guess: ")
-
guess = guess.lower()
-
-
elif guess ==hint and word =="answer":
-
print "solution"
-
guess = raw_input("Your guess: ")
-
guess = guess.lower()
-
-
else:
-
print "Musical instrument that consists of bars of various lengths."
-
guess = raw_input("Your guess: ")
-
guess = guess.lower()
(Also, the test in the while loop should probably have an or in front of the hint check, instead of an and.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: C# Learner |
last post by:
Why is C syntax so uneasy on the eye?
In its day, was it _really_ designed by snobby programmers to scare away
potential "n00bs"? If so, and after 50+ years of programming research,
why are...
|
by: Joe |
last post by:
Is Python going to support s syntax the does not use it's infamous
whitespace rules? I recall reading that Python might include such a
feature. Or, maybe just a brace-to-indentation preprocessor...
|
by: smichr |
last post by:
I have (inadvertently) wiped out the functionality of my personal
python snippets by eliminating leading space. I have also just visited
http://www.python.org/tim_one/000419.html and saw a piece of...
|
by: diffuser78 |
last post by:
I am a newbie to Python. I am mainly using Eric as the IDE for coding.
Also, using VIM and gedit sometimes.
I had this wierd problem of indentation. My code was 100% right but it
wont run...
|
by: Jim |
last post by:
Could somebody tell me why I need the "elif char == '\n'" in the
following code?
This is required in order the pick up lines with just spaces in them.
Why doesn't
the "else:" statement pick this...
|
by: Charles Sullivan |
last post by:
I'm trying to maintain some older C code (FOSS) which has been
patched by various individuals over the years for portability to
multiple Unix-like operating systems, to wit: Linux, SunOS,
Solaris,...
|
by: juan-manuel.behrendt |
last post by:
Hello together,
I wrote a script for the engineering software abaqus/CAE. It worked
well until I implemented a selection in order to variate the variable
"lGwU" through an if elif, else...
|
by: bvdet |
last post by:
We are parametrically attaching a bent plate object to the side of a building column for support of a skewed beam. Given a relative rotation between the column and beam and which side of the column...
|
by: Eric S. Johansson |
last post by:
Almar Klein wrote:
there's nothing like self interest to drive one's initiative. :-) 14 years with
speech recognition and counting. I'm so looking to my 15th anniversary of being
injured next...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| | |