Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My Code isn't working...
#1
Hi. I am new to Python so I'm not that skilled. As I was coding my game, I realised something was up. When I went to play it and I inserted my name, nothing happened afterwards. Can someone please help me?

My Code:
print("---- SPIRIT DUNGEONS COMING SOON ----")
question = input("Story Mode or Dungeons?")
if question == "Story Mode":
  question = input("What Chapter?")
if question == "1":
  question = input("Please enter your name... ")
  if question == "0318":
    print("Wait..what just happened? Looks like you've been teleported to a mysterious locker...it smells very putrid...")
    question = input("Will you open it? Yes/No")
    if question == "Yes":
     print("Collected Knife 1/3!")
     question = input("Please enter your name...")
    if question == "No":
     question = input("Please enter your name...")
    print "Welcome", question + ". You find yourself stuck in a haunted mansion. There are ghosts and demons hiding in every alleyway so to escape, you musn't make  a wrong turn."
else:
  print "Welcome", question + ". You find yourself stuck in a haunted mansion. There are ghosts and demons hiding in every alleyway so to escape, you musn't make  a wrong turn."
  question = input("Left or Right? ")
  if question == "Left":
     print("There was a ghost...You Died! Press the STOP button two times to restart!")
     if question == "Right":
      print("Good decision.")
      No = input
      question = input("You found a set of stairs. Do you go down them? Yes/No")
      if question == "No":
        print("Oh no! There is a demon! Looks like you're dead...Press the STOP button two times to restart!")
      if question == "Yes":
       print("Nice job!")
       Fight = input
       question = input("Oh no! You've encountered a ghost! Run or Fight? Run/Fight")
       if question == "Fight":
         print("You couldn't even land a single hit on it! Better luck next time! Press the STOP button two times to restart!")
       if question == "Run":
         print("You ran faster than you ever have and the ghost couldn't keep up! Nice running!")
         No = input
         question = input("You see a knife on the kitchen table. Do you pick it up? Yes/No")
         if question == No:
           print("Huh...")
         else:
           print("Collected Knife 2/3!")
           Yes = input
           question = input("Search the drawers for more? Yes/No")
           if question == "Yes":
             print("Collected Knife 3/3!...")
             Run = input
             question = input("...but a ghost came out! Run/Fight?")
             if question == "Run":
               print("Well, looks like the ghost caught up this time! Press the STOP button two times to restart!")
             if question == "Fight":
               print("Looks like that new knife came in handy! You defeated it!")
               print("You picked up a Ghost Soul!")
               print("Ghost Souls can be used to reforge your sword if it breaks.")
               print("It looks like the door is not far away!...but you'll need to get through a couple more rooms.")
               question = input("Enter Bathroom or Living Room?")
               if question == "Bathroom":
                 question = input("Pick up Soap Bar? Yes/No")
                 if question == "Yes":
                   print("You picked up a Soap Bar!")
                 question = input("A Wild Demon Appeared! What do you do? Fight/Block")
                 if question == "Fight":
                   print("You threw the Soap Bar at it! You Died! Press the STOP button two times to restart!")
                 if question == "Block":
                   print("Nice job! You blocked it's attack! Now hit it with your knife while it's paralysed!")
                   question = input("Type KNIFE to defeat it!")
                   if question == "KNIFE":
                     print("Good Job! You killed it!...literally!")
                     print("Just one more room to go!")
                     question = input("Basement or Bedroom?")
                     if question == "Basement":
                       print("It's dark..you can't see anything...where is the light?")
                       print("...")
                       print("...")
                       print("...")
                       print("AHHH!! YOU GOT JUMPSCARED BY A GHOUL.")
                       print("It's trying to posess you!")
                       question = input("Think fast! Fight/Block")
                       if question == "Fight":
                         print("You hit it!..but it broke! It did no damage!")
                         print("I would use that Ghost Soul right about now if I were you...!")
                         question = input("Use Ghost Soul? Yes/No")
                         if question == "Yes":
                           print("Sword Repaired! It's 25x stronger than it was before! Oops, I may have forgotten to tell you, if you use your Ghost Soul it will not only reforge your sword, but it will make it 2x-50x stronger!")
                           question = input("Quick! Fight/Block")
                           if question == "Fight":
                             print("...")
                             print("It's...")
                             print("it's..dead...")
                             print("You did it! Now just head to the door!")
                             question = input("Exit Haunted Mansion?")
                             if question == "Yes":
                               print("Developed by -")
                               print("Thanks for Playing!")
                               print("G A M E  O V E R")
                               print("0318?")
I didn't get an error message.
Yoriz write Mar-18-2022, 01:35 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
There's a lot of code there, so the question is what have you done by to debug the problem? Did it stop working after you changed something? What changed? You could learn about version control (e.g. with Git) to help you keep track of your changes, so you can go back to an earlier version.

Later on, when you're more experienced with be programming, you can learn about writing automated tests to help you keep code working as you change it.

Lastly, when posting code here, please use Python tags (use the Python button to insert them) around your code to keep the formatting and add syntax highlighting and line numbering.
Reply
#3
(Mar-18-2022, 10:56 AM)End3r Wrote: When I went to play it and I inserted my name, nothing happened afterwards.
That is correct. And note it only asks for your name if you had answered the previous questions with "Story Mode" and chapter "1". If you would give "0318" as your name, then the next question would come up. But if you answered something else, then no questions would follow in this block.
The "name" question is in the 'if question == "1"' block so from line 6 to 15. Then there is an 'else' block which is executed when 'chapter "1"' is not chosen. This 'else' block runs from line 17 to the end.
So it is correct, after answering "End3r" as your name, the program ends.
Reply
#4
You have an indentation error:
if question == "1":
  question = input("Please enter your name... ")
  if question == "0318":
    print("Wait..what just happened? Looks like you've been teleported to a mysterious locker...it smells very putrid...")
    question = input("Will you open it? Yes/No")
    if question == "Yes":
     print("Collected Knife 1/3!")
     question = input("Please enter your name...")
    if question == "No":
     question = input("Please enter your name...")
    print "Welcome", question + ". You find yourself stuck in a haunted mansion. There are ghosts and demons hiding in every alleyway so to escape, you musn't make  a wrong turn."
else:
After picking chapter 1 and entering you name you have reached the end of your program. There are no remaining branches. The following "else:" is the alternative to "if question == "1":" on line5.

But indentation is the smallest of your problems. Your problem is not your ignorance of Python. Your overall game design is bad. You cannot write a game where game flow is controlled by a series of if statements. Even a small number of choices quickly leads to a large number of branches. The code below is quickly growing even though it isn't close to covering all possible answers to "Would you like a bagel and some water to go with it?"
if input("Do you want water? ") == "Yes":
    if input("Do you want to dring the water now? ") == "Yes":
        if input("Do you want a bagel?") == "Yes":
            if input("Would you like that toasted? ") == "Yes":
                if input("Do you want to eat the bagel now? ") == "Yes":
                    print("Did you enjoy your water and toasted bagel?")
            else:
                if input("Do you want to eat the bagel now? ") == "Yes":
                    print("Did you enjoy your water and untoasted bagel?")
else:
    if input("Do you want a bagel?") == "Yes":
        if input("Would you like that toasted? ") == "Yes":
            if input("Do you want to eat the bagel now? ") == "Yes":
                print("Did you enjoy your toasted bagel?")
        else:
            if input("Do you want to eat the bagel now? ") == "Yes":
                print("Did you enjoy your untoasted bagel?")
Games require a different way of programming. There are numerous blogs, tutorials and web sites that discuss how to write games. I suggest you find a few you like, work through a tutorial or two. Then try writing you own game.
Reply
#5
(Mar-18-2022, 10:56 AM)End3r Wrote: Hey guys, thanks to you guys, I fixed my game. I appreciate all of the help I got and I know my game design isn't perfect and I am going to try to improve it later on.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  New to Python - Not sure why this code isn't working - Any help appreciated TheGreatNinx 4 962 Jul-22-2023, 10:21 PM
Last Post: Pedroski55
  code not working when executed from flask app ThomasDC 1 892 Jul-18-2023, 07:16 AM
Last Post: ThomasDC
  I am new to python and Could someone please explain how this below code is working? kartheekdas 2 1,017 Dec-19-2022, 05:24 PM
Last Post: kartheekdas
Exclamation My code is not working as I expected and I don't know why! Marinho 4 1,083 Oct-13-2022, 08:09 PM
Last Post: deanhystad
  I don't undestand why my code isn't working. RuyCab 2 1,992 Jun-17-2021, 03:06 PM
Last Post: RuyCab
  code is not working , can anybody help? RandomPerson69 4 2,913 Mar-22-2021, 04:24 PM
Last Post: deanhystad
  Short code for EventGhost not working Patricia 8 3,691 Feb-09-2021, 07:49 PM
Last Post: Patricia
  Code no longer working yk303 14 10,182 Dec-21-2020, 10:58 PM
Last Post: bowlofred
  autocomplete working code sample not working... aviper4u 0 1,642 Oct-24-2020, 03:04 AM
Last Post: aviper4u
  code not working, NameError: name 's' is not defined ridgerunnersjw 4 3,822 Oct-05-2020, 07:03 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020