I have this code, it's basically a program which I wrote, a 'Guess my number' game. The only problem is that I did something, and now I can't choose from my options anything else, that the first option. I put all my conditions in the while True loops, and now it won't let me choose anything else, just the first thing from the while. The same thing goes for the end of one level, meaning at the question "Redo", even thou I put the No answer it won't break, it will still get the first instruction to run, meaning the call to the program. If I'm not clear enough, let me know, I will try to explain better.
Here's the code:

'''
Created on Feb 15, 2012

@author: sin
'''
import random
import sys
import time
class guess:
    def __init__(self):
        pass
    def showUi(self):
        while True:
            print """
    Welcome to Guess my number."""
            self.name = raw_input("What is your name? \n")
            print "Greetings", self.name, "and welcome to Guess my number."
            print """
    The game is really simple. First, you have to choose a level, than at each level, depending, you will have
    to guess a number which I will randomly choose. Don't worry if you don't get if from the first time, I will
    be instructing you if your guess is higher or lower of the chosen number. Note that you have limited guesses
    per each level, so try not to guess foolishly. 
    Well, enough talk, let's see the menu.
            Levels:
            1. Level 1 - Easy level, with numbers in range of 0 to 20, and with 6 guesses.
            2. Level 2 - Medium level, with numbers in range of 0 to 30, and with 6 guesses.
            3. Level 3 - Hard level, for players in luck, with numbers in range of 0 to 100, and with 5 guesses.
            """
        
            cmd = raw_input("Please, insert your command: ")
            if cmd == "1" or "1.":
                self.level1()
            if cmd == '' or "":
                print "Please, insert your name."
            if cmd == "2" or "2.":
                self.level2()
            if cmd == "3" or "3.":
                self.level3()
            if cmd == "exit" or "EXIT" or "quit" or "destroy" or "bambucha" or "detonate" or "kill" or "explode":
                sys.exit()
            
    def redo(self):
        print """
        Levels:
        1. Level 1 - Easy level, with numbers in range of 0 to 20, and with 6 guesses.
        2. Level 2 - Medium level, with numbers in range of 0 to 30, and with 6 guesses.
        3. Level 3 - Hard level, for players in luck, with numbers in range of 0 to 100, and with 5 guesses.
        """
        while True:
            cmd = raw_input("Please, insert your command: ")
            if cmd == "1" or "1.":
                self.level1()
            elif cmd == "2" or "2.":
                self.level2()
            elif cmd == "3" or "3.":
                self.level3()
            elif cmd == "exit" or "EXIT" or "quit" or "destroy" or "bambucha" or "detonate" or "kill" or "explode":
                sys.exit()
            
    def level1(self):
        guesstaken = 0
        print "Ok", self.name + ',', "you chose level 1. Lets see if you can guess my number."
        print "I will think of a number between 0 and 20, and you have 6 tries to guess that number."
        
        number = random.randint(0, 20)
        
        while guesstaken < 6:
            guess = int(raw_input("Take a guess: \n"))
            guesstaken += 1
            if guess < number: print "Your guess is lower than the number I've chosen."
            elif guess > number: print "Your guess is higher than the number I've chosen."
            else: break
        
        if guess == number:
            print "Congratulation", self.name, "you have guessed my number,", str(number) + ',', "from ", guesstaken, "guesses."
        else: print "I am sorry. The number I choose was", str(number) + '.', "Unfortunately you're out of tries, better luck next time." 
        d = raw_input("Try again? Y/N. \n")
        if d == "Y" or "y" or "Yes" or "Ok" or"ok" or"Sure":
            self.redo()
        elif d == "n" or "N" or "No" or "no":
            "Thank you", self.name, "for playing Guess my number."
            sys.exit()
        else: sys.exit()
    

    def level2(self):
        guesstaken = 0
        print "Ok", self.name + ',', "you chose level 2. Lets see if you can guess my number."
        print "I will think of a number between 0 and 40, and you have 8 tries to guess that number."
        
        number = random.randint(0, 40)
        
        while guesstaken < 8:
            guess = int(raw_input("Take a guess: \n"))
            guesstaken += 1
            if guess < number: print "Your guess is lower than the number I've chosen."
            elif guess > number: print "Your guess is higher than the number I've chosen."
            else: break
        
        if guess == number:
            print "Congratulation", self.name, "you have guessed my number", str(number) + ',', "from ", guesstaken, "guesses."
        else: print "I am sorry. The number I choose was", str(number) + '.', "Unfortunately you're out of tries, better luck next time."
        d = raw_input("Try again? Y/N. \n")
        if d == "Y" or "y" or "Yes" or "Ok" or"ok" or"Sure":
            self.redo()
        else:
            "Thank you", self.name, "for playing Guess my number."
            time.sleep(3)
            exit()
    
    def level3(self):   
        guesstaken = 0
        print "Ok", self.name + ',', "you chose level 3. Lets see if you can guess my number."
        print "I will think of a number between 0 and 100, and you have 10 tries to guess that number."
        
        number = random.randint(0, 100)
        
        while guesstaken < 10:
            while guess != '':
                guess = int(raw_input("Take a guess: \n")) 
                guesstaken += 1
                if guess < number: print "Your guess is lower than the number I've chosen."
                elif guess > number: print "Your guess is higher than the number I've chosen."
                else: break
        
        if guess == number:
            print "Congratulation", self.name, "you have guessed my number", str(number) + ',', "from ", guesstaken, "guesses."
        else: print "I am sorry. The number I choose was", str(number) + '.', "Unfortunately you're out of tries, better luck next time."
        d = raw_input("Try again? Y/N.\n")
        if d == "Y" or "y" or "Yes" or "Ok" or"ok" or"Sure":
            self.redo()
        else:
            "Thank you", self.name, "for playing Guess my number."
            time.sleep(3)
            exit()
    
m = guess()
m.showUi()

Never mind, I found the problem. It was just that in my while instructions, the actual instructions are written wrong... meaning that for example, if cmd=='1' or '1.': it's actually if cmd== '1' or cmd=='1.': ...
Huh, silly me:D

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.