-1

The if statement in Cloud3 keeps returning the else branch even though I entered 2500 exactly.I don't know how to fix this.I have assigned a value of 2500 to square and then set raw_input to answer2 so if answer2==square, it should have been true and executed the first if branch.

Also, I copied the RealEngine and CloudEngine classes because I couldn't understand them. So I would appreciate if someone could explain what is going on with them.This whole script is a text-based game.

from sys import exit
from random import randint

class Smaker(object):
    def enter(self):
        print "whatever"
        exit(1)
class RealEngine(object):
    def __init__(self,scene_map):
        self.scene_map=scene_map
    def start(self):
        current_scene=self.scene_map.opener()
        while True:
            print "\n--------------"
            upcomingscene=current_scene.enter()
            current_scene=self.scene_map.play(upcomingscene)

class Slyremarks(Smaker):
    slyremarks=["My mom is better at this than you.",
                "You Dame ningen",
                "Seriously, how lame can a guy get???",
                "I thought you were better than this.",
                "Cheryl is really gonna be in trouble for recruiting such a 
                noob",
                "*Stares in disbelief*",
                "HAHAHAHAHAHAHAH,LOSERRRRRRRR!",
                "You seriously thought you could beat this game???",
                "Man, I'm gonna make this a meme and send this to God to 
                brighten up his day"]

    def enter(self):
        print Slyremarks.slyremarks[randint(0,len(self.slyremarks)-1)]
        exit(1)


class Cloud1(Smaker):
    def enter(self):
        print "You are being sent to  heaven after you died of diabetes,"
        print  "you fat shit.You should be ashamed of yourself."
        print "Anyway your at the gates of heaven and the guy at the gate 
              asks"
        print "you a question.'what do you want,a hotel or a mansion?'"
        print "What do you want? The simplicity of a motel or a damn 
               mansion?"
        answer=raw_input(">")
        if answer=="mansion":
            print "DUUH.I thought so.You magically teleport to your mansion 
                   that is made of gold and"
            print "diamonds but wait!!God says you have to go 
                   complete the challenge of the 9 clouds"
            print "before you can live it up in paradise."
            print "You're already on cloud 1, now the trial begins in 
                   cloud2"
            return 'cloud2'
        elif answer=="motel":
            print "Your simplistic tastes are beyond me but because of your 
                   odd ,choice the giant"
            print "gatekeeper laughs so hard he makes you fall of the cloud 
                   and inflict permadeath on you"
            return 'marks'

class Cloud2(Smaker):
    def enter(self):
        print "God says:OKAY!For the first test I want you to do a backflip 
              or  frontflip"
        print "which do you want to do?"
        action=raw_input(">")
        if action=="backflip":
            print "You stick the landing like a boss but God,being a fickle 
                   being,decided that it"
            print "Was boring and damns you to spend eternity in a motel 
                   kitchen;serving others"
            return 'marks'
        elif action=="frontflip":
            print "You fail miserably and smash your front teeth on the 
                   pavement"
            print "Yes, heaven has pavement.But you made God laugh 
                   hysterically and "
            print "so he rewards you with passage to cloud 3"
            return 'cloud3'

class Cloud3(Smaker):
    def enter(self):
        square=2500
        self.square=square
        print "For this cloud you have to solve a math problem:"
        print "What is:the square of 50?"
        answer2=raw_input(">")
        if answer2==square:
            print "Correct!!"
            print "WOW you must be some sort of math wiz!!"
            return 'trap'
        else:
            print "Wrong.You die."
            print "Like have you ever even been to school???"
            return 'marks' 
class trapfall(Smaker):
    pass
class Cloud4(Smaker):
    pass
class Cloud4(Smaker):
    pass
class Cloud5(Smaker):
    pass
class Cloud6(Smaker):
    pass
class Cloud7(Smaker):
    pass
class Cloud8(Smaker):
    pass
class Cloud9(Smaker):
    pass
class CloudEngine(object):
    clouds=  {'cloud1':Cloud1(),
            'cloud2':Cloud2(),
            'cloud3':Cloud3(),
            'cloud4':Cloud4(),
            'cloud5':Cloud5(),
            'cloud6':Cloud6(),
            'cloud7':Cloud7(),
            'cloud8':Cloud8(),
            'trap':trapfall(),
            'cloud9':Cloud9(),
            'marks':Slyremarks()}
    def __init__(self,start_scene):
        self.start_scene=start_scene
    def play(self,scene):
        return CloudEngine.clouds.get(scene)
    def opener(self):
        return self.play(self.start_scene)
ooh=CloudEngine('cloud1')
asldkfj=RealEngine(ooh)
asldkfj.start()
b1lal555
  • 1
  • 2

2 Answers2

3

raw_input returns a str type, you will need to convert it to int.

XPLOT1ON
  • 2,994
  • 2
  • 20
  • 36
1
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> raw_input(">")
>2500
'2500'
>>> raw_input(">") == "2500"
>2500
True
>>> raw_input(">") == 2500
>2500
False
>>> 
Erich
  • 1,902
  • 1
  • 17
  • 23