1

I'm not sure what in my code is wrong but it doesn't return the print statements. Any help is appreciated. edit 1: Adding firstpath(input1) vs firstpath() at the end does nothing edit 2: thanks gene for the correct response! print("Welcome to (insert title here)\n\n") input1 = input("You are walking down a street, and suddenly hear a loud bang. Type Y to investigate or N to ignore: ") def firstpath(input1): if input1 == "Y": print("You walk towards the sound") elif input1 == "N": print("You continue down your path") firstpath()

2
  • Are you calling firstpath(input1) anywhere? Try adding that after the code. Commented Jul 8, 2020 at 0:16
  • Looks like the indentation might just be off - the firstpath() at the end is within the function definition. Try tabbing that back out and including input1 as a parameter of the function as suggested above. Commented Jul 8, 2020 at 0:21

4 Answers 4

2

Your code maybe should've been:

print("Welcome to (insert title here)\n\n")
input1 = input("You are walking down a street, and suddenly hear a loud bang. Type Y to investigate or N to ignore: ").lower()
def firstpath(local_input):
    if local_input == "y":
        print("You walk towards the sound")
    elif local_input == "n":
        print("You continue down your path")
    else:
        print('Sorry, bad answer.')
firstpath(input1)
Sign up to request clarification or add additional context in comments.

Comments

1

Call firstpath() outside the function definition. You should also add else condition to your code for it to work properly.!

print("Welcome to (insert title here)\n\n")
input1 = input("You are walking down a street, and suddenly hear a loud bang. Type Y to investigate or N to ignore: ")
def firstpath(input1):
    if input1 == "Y":
        print("You walk towards the sound")
    elif input1 == "N":
        print("You continue down your path")
    else:
        print("Please enter either Y or N")
firstpath(input1)

10 Comments

still did nothing
the added else worked, thank you!!! I don't get what I was doing wrong tho
@CranberryJuice The input1 global variable and the input1 local variable is causing some ambiguity.
But how else would that work? Should I put input statements inside my function ?
@CranberryJuice Else means everything else. Like if the top two were False
|
0
print("Welcome to (insert title here)\n\n")
input1 = input("You are walking down a street, and suddenly hear a loud bang. Type Y to investigate or N to ignore: ")
def firstpath(input1):
    if input1 == "Y":
        print("You walk towards the sound")
    elif input1 == "N":
        print("You continue down your path")
firstpath(input1)

1 Comment

Traceback (most recent call last): File "C:/Users/kmd20/Desktop/Python Projects/textbasedadventure/gam.py", line 8, in <module> firstpath() TypeError: firstpath() missing 1 required positional argument: 'input1'
0

You are calling firstpath(input1) within the function. Try this:

print("Welcome to (insert title here)\n\n")
input1 = input("You are walking down a street, and suddenly hear a loud bang. Type Y to investigate or N to ignore: ")
def firstpath(input1):
    if input1 == "Y":
        print("You walk towards the sound")
    elif input1 == "N":
        print("You continue down your path")
firstpath(input1)

2 Comments

nope doesn't work, just ignores everything and gives me Process finished with exit code 0
It worked for me--maybe this has something to do with the version of python you are running it in?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.