473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

While statement returns false even if it's true

Even when the jumble is solved correctly, the program prints the try again message. What am I missing.


Expand|Select|Wrap|Line Numbers
  1.  
  2. # Led Zeppelin Word Jumble
  3. # to utilize loops, strings and tupules
  4. # Nathan Porter
  5. # 10/03/2011
  6.  
  7. import random
  8.  
  9. # create a sequence of words to choose from
  10. words = ("Robert Plant", "Jimmy Page", "John Bonham", "John Paul Jones",)
  11. hints = {"Robert" : "The greatest voice in rock",
  12.                "Jimmy" : "Yardbird",
  13.                "Bonham" : "R.I.P.  25 September 1980",
  14.                "Jones" : "triquetra"}
  15. word = random.choice(words)
  16. hint = 'hint'
  17. correct = word
  18. word1 = word
  19. count = 1
  20.  
  21.  
  22. # create a jumbled version of the word
  23. jumble =""
  24.  
  25. while word:
  26.     position = random.randrange(len(word))
  27.     jumble += word[position]
  28.     word = word[:position] + word[(position + 1):]
  29.  
  30.  
  31. score = 0
  32.  
  33. # start the game
  34. print(
  35. """
  36.            Welcome to Led Zeppelin Word Jumble!
  37.  
  38.    Unscramble the letters to make a word.
  39.    Type 'hint' for help or just press Enter to give up
  40.  
  41. """
  42. )
  43. print("\nThe jumble is:", jumble)
  44.  
  45. guess = input("Your guess:\n>>>")
  46. guess = guess.lower()
  47. if guess == "":
  48.     print ("You Lose!"),
  49. elif guess == hint:
  50.         if word1 == 'Robert Plant':
  51.             print (hints,("Robert"))
  52.         elif word1 == 'Jimmy Page':
  53.             print (hints,("Jimmy"))
  54.         elif word1 == 'John Bonham':
  55.             print (hints,("Bonham"))
  56.         elif word1 == 'John Paul Jones':
  57.             print (hints,("Jones"))
  58. while (guess != correct) and (guess != ""):
  59.     print ("Lots of people talk but few of them know...")
  60.     guess = input("Your guess:\n>>>")
  61.     guess = guess.lower()
  62.  
  63.     if guess == correct:
  64.         print ("...and it only goes to show, you know!\n"),
  65.  
  66.  
  67.  
  68. print("Thanks for playing") 
  69.  
  70. input("\n\nPress the enter key to exit.")
  71.  
Oct 13 '11 #1
4 1710
Rabbit
12,516 Expert Mod 8TB
Odd coding choices aside, you convert the guess to lower case letters while your words are not.
Oct 13 '11 #2
I'm teaching myself out of this book and using this forum. I'm having a hard time with it. What choices are odd?
Oct 13 '11 #3
thank you for your help, I finally got it to work correctly, there was a problem with my elif statements as well
Oct 13 '11 #4
Rabbit
12,516 Expert Mod 8TB
Some of the odd choices are that you have 3 variables that store the word choice. At most you need 2. Also, you have a variable count and score that you never use.

Some more advanced stuff is that you can combine the words dictionary with the hint dictionary. You can also use the key to get the hint rather than using that if elif structure.

But none of that stuff actually affects whether or not the code works. Glad you got it fixed, good luck.
Oct 13 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Joan | last post by:
I am creating a word document from an asp page. I have no problems actaully creating the document and creating some tables that have data in them. I am using Response.ContentType =...
2
by: bekil | last post by:
I have a problem with landscape pages in word document. I am creating a word document using asp programming. I want to set n. page as a landscape. But I can not do it. for example I want to...
10
by: Douglas G | last post by:
I've tried various ideas on this problem, but I don't see word wrapping. Can you point out what is wrong? It's a K&R exercise, and I'm still new to programming. Other pointers would be helpful...
0
by: mharris | last post by:
I need help with merging two Word documents into one through C# code. The problem isn't so much getting the documents put into one as it is maintaining the appropriate formatting, or rather...
0
by: Raj Singh | last post by:
I am facing a problem with Visual C# 2003 and MS Word XP. I am using a customized template for Word and in that template I have defined some bookmarks. I am trying to create a Word document based...
0
by: Youss33 | last post by:
I have a problem printing a word document from an ASP.NET application. the Application doesn't send an error back but the document is not printed and the document is kept open by the application...
0
by: Maileen | last post by:
Hi, I try to add/modify some style in Word 2002 and 2003 using VB, but I have such error : System.runtime.interopServces.COMException(0x800A1735) : Given Items does not exist. at...
2
by: matt.whitby | last post by:
Hello there. Not sure if you've time to read this, but i'm having a problem. I have a test application with the following code (see below). I have run the app on thirteen machines and on eight...
5
by: momo | last post by:
say i have the following table: <table width="500"> <tr> <td width="250">this is the text im concerned with</td> <td></td> </tr> </table> i need the width of the columns to STAY at 250 and...
8
by: Cjllewey369 | last post by:
I am working on learning Python out of a book called Python Programming for the Absolute Beginner. Right now I am working on a challenge at the end of one of the chapters. During the chapter i was...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.