2017-08-16 2 views
0

Cloudboxのif文は、2500を正確に入力したにもかかわらずelseブランチを返し続けます。これを修正する方法はわかりません.2500の値をsquareに割り当て、次にraw_inputをanswer2に設定します。したがって、answer2 == squareの場合、それは真であり、最初の分岐の場合に実行されます。文が偽を返し続けている場合

また、RealEngineクラスとCloudEngineクラスは、わかりませんでしたのでコピーしました。ですから、もし誰かが何が起こっているのかを説明できるのであれば、私は感謝します。このスクリプト全体は、テキストベースのゲームです。

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

'raw_input()'は文字列を返します。これはintと同じではありません – TemporalWolf

+0

'asldkfj'のような変数名を使わないことをお勧めします。 – TemporalWolf

答えて

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 
>>> 
3

raw_inputstr型を返す、あなたはintに変換する必要があります。

関連する問題