-3

Want to have a system where it records how many attempts for each room, as well as being able to repeatedly ask for what you want to look at in each room.

I wanted to have something that has a 3 room system, record how many attempts it took to get to the next room, display them at the end, while also asking for if you'd like to continue looking at other things in the room, or try the password and then proceed to the next room. Any feedback welcome, I haven't touched Python in years, it's also a bit silly because his favorite animal is a duck. I'm using Renpy.

This is my code so far:

#escaping the ducks. they are chasing and honking at you. but youre stuck
print("Welcome to your Escape Room! You've entered a room to escape the duck.")
print("It honks angrily.")

r1attempts = 0
r2attempts = 0
r3attempts = 0
#first room has the number 78225, which means quack in numbers

userName = input("Before we get started, whats your name? ")
print("Thank you, " + userName)
print("You enter the first room, where you look around. Theres a few things to see.")
def room1():
  
  print("You can look under the table, at the ceiling, or at the door infront of you. You can also attempt the password.")
  print("Which do you choose?")
  #this is where i want it to keep asking

def r1pass(p):
  
    password = "78225"
    print("You look at the numberpad.")
  
    while (password != p) :
      p = input("What is your input? ")
      if (password != p ):
        print("Incorrect. Please try again.")
        r1attempts + 1
        return False
      elif (password == p):
        print("The door creaks open.")
        print("It took you " + r1attempts + " to guess the password for Room 1!")
        return True
      
      
  
tcde = ['Table', 'Ceiling', 'Door', 'Password']
room1()
choice1 = input("Please type 'Table', 'Ceiling', or 'Door' to look at the respective. Or, you can attempt the password by typing 'Password'. ")


if(choice1 == "Table"):
  print("You look at the table. It doesn't seem to have anything but a strange number.")
  print("Scratched into the wood, faintly, it looks like 78225")
  room1()
  
elif(choice1 == "Ceiling"):
   print("You look at the ceiling. It seems to have a morse code in the popcorn ceiling, if you squint.")
   print("It looks like the morse code spells out the numbers 3825. Whatever that means.")
   room1()
  #Its the numbers for the word Duck!

elif(choice1 == "Door"):
  print("You look at the door. It seems to have a numberpad, with letters under each number.")
  print("The number pads 4, 6, 5, 3, and 7 seem worn.")
  room1()
  #This is misleading. whoever was before you tried to enter honker. it didnt work. two of these hints are red herrings.

elif(choice1 == "Password"):
  r1pass()
  
else:
  print("That didn't seem to be a valid answer. Please make sure you type the options listed above.")
  room1()


#secound room asks how many more pounds of eggs can a duck lay in a year than the best laying chicken breed, which is 18
#third room asks for the player to pick up a golden egg or leave it, if you leave it, youll live and if you pick it up the quacker gets you

Unfortunately, it yeilds result of successfully returning the first wave of asking what choice you want, but gets as far as that and if it asks a secound time, it gives a error message of something like this,

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'Ceiling' is not defined

Any help greatly appreciated.

buran
  • 13,682
  • 10
  • 36
  • 61
accentbee
  • 3
  • 3
  • [Please do not upload images of code/data/errors.](//meta.stackoverflow.com/q/285551) – buran Apr 14 '23 at 04:30
  • You are running this in python2, when it should be run in python3. In python2 you should be using `raw_input`, not `input`. Just use python3 – buran Apr 14 '23 at 04:35
  • Thank you for the feedback! I will remove the image and put the description of the code in the post instead. Thank you though! I will try to edit the inputs to raw_input because I do not think there is an option to change to Python 3 in Replit. – accentbee Apr 14 '23 at 04:41
  • I think there is, but in any case - if there is not, move away, python2 i dead since 2020 – buran Apr 14 '23 at 04:43
  • I changed it to 3.10.8 and it had the same problem – accentbee Apr 14 '23 at 04:50
  • 1
    No, it does not. Execution ends, after asking/printing second time "Which do you choose?" (from calling `room1()`), but does not raise any error. That is expected given the code - you just call `room1()` which has just 2 prints – buran Apr 14 '23 at 05:59
  • If you're still seeing the same problem, then you are not using Python 3. – Tim Roberts Apr 14 '23 at 06:05

1 Answers1

0

I think you want to put all the room1 functionality together and loop over it until the password it correct, something like this:

def room1():
  
    print("You enter the first room, where you look around. Theres a few things to see.")
    print("You can look under the table, at the ceiling, or at the door infront of you. You can also attempt the password.")
    print("Which do you choose?")
    while True:
        choice1 = input("Please type 'Table', 'Ceiling', or 'Door' to look at the respective. Or, you can attempt the password by typing 'Password'. ")


        if(choice1 == "Table"):
            print("You look at the table. It doesn't seem to have anything but a strange number.")
            print("Scratched into the wood, faintly, it looks like 78225")
        
        elif(choice1 == "Ceiling"):
            print("You look at the ceiling. It seems to have a morse code in the popcorn ceiling, if you squint.")
            print("It looks like the morse code spells out the numbers 3825. Whatever that means.")
            #Its the numbers for the word Duck!

        elif(choice1 == "Door"):
            print("You look at the door. It seems to have a numberpad, with letters under each number.")
            print("The number pads 4, 6, 5, 3, and 7 seem worn.")
            #This is misleading. whoever was before you tried to enter honker. it didnt work. two of these hints are red herrings.

        elif(choice1 == "Password"):
            if r1pass():
                return
        
        else:
            print("That didn't seem to be a valid answer. Please make sure you type the options listed above.")


def r1pass():
  
    password = "78225"
    p = None
    print("You look at the numberpad.")
  
    while (password != p) :
      p = input("What is your input? ")
      r1attempts += 1
      if (password != p ):
        print("Incorrect. Please try again.")
        r1attempts + 1
        return False
      else:
        print("The door creaks open.")
        print(f"It took you {r1attempts} to guess the password for Room 1!")
        return True
      
      
if __name__ == '__main__':
    #escaping the ducks. they are chasing and honking at you. but youre stuck
    print("Welcome to your Escape Room! You've entered a room to escape the duck.")
    print("It honks angrily.")

    r1attempts = 0
    r2attempts = 0
    r3attempts = 0
    #first room has the number 78225, which means quack in numbers

    userName = input("Before we get started, whats your name? ")
    print("Thank you, " + userName)

    room1()
DobbyTheElf
  • 604
  • 6
  • 21