Python misbehaving


#1



no link

something about the parentheses?
if input == ("Good, thank you")
SyntaxError: invalid syntax

It is supposed to run correctly


def main():
    print("How's your day?")
    if input == ("Good, thank you")
        print("No problem")
    elif input == ("Good, thank you!")
        print("No problem!")
    elif input == ("It was great!")
        print("Oh, really? Good for you!")
    elif input == ("It was great, thank you!")
        print("Good to hear!")
    elif input == ("It was great")
        print("Oh, really? Good for you!")
    elif input == ("It was great, thank you")
        print("Good to hear!")
    else input == ("see you later!")
main()
input("Press Enter or Return to end!")


#3

what do you mean the whole condition?


#5

thank you! but now it says something about the t in input (line 15)


#7


#8

This is comparing a variable named input to a string, but

this is calling a function called input...

Which was it supposed to be?


#9

else doesn't take a condition.


#10

ohhhh right! thanks a lot!!!!


#11

wait, i changed that to else print("see you later!"), and it selects the end of print again.


#12

i replaced print with input, same thing...


#13

spaces has nothing to do with it...


#14

Try:
→ giving main() a parameter of input.
→ putting a colon : at the end of each line starting with if, elif or else.
→ changing the else part to:

else:
    input = "See you later!"

→ calling the main() function with a parameter (for example main("Good, thank you"))
→ removing the input(...) at the end.


#15

thanks! now it displays though


#16

do i have to make it wait?


#17

Try:

def main(input):
    print("How's your day?")
    if (input == "Good, thank you"):
        print("No problem")
    elif (input == "Good, thank you!"):
        print("No problem!")
    elif (input == "It was great!"):
        print("Oh, really? Good for you!")
    elif (input == "It was great, thank you!"):
        print("Good to hear!")
    elif (input == "It was great"):
        print("Oh, really? Good for you!")
    elif (input == "It was great, thank you"):
        print("Good to hear!")
    else:
        print("See you later!")
main("Good, thank you") #should print "No problem"

#18

HERE!!!!!!!!!!!!!!!!!!!!!!
HERE!!!!!!!!!!!!!!!!!!!!!!
HERE!!!!!
HERE!!!!!
i can't post that many comments, so im editing, but thanks, it works.


#19

It should only print once, but it might show it twice because of the way that the console returns things. Does it pass?


#20

With all the possible variables one could use, is it really necessary to use a reserved word? Why confuse yourself or your reader?

user = input('...")

If you want to allow user input, then do it before the function call, not after. Code executes top down.

def main(us):
    # code

user_input = input(" ... ")
main(user_input)

Since this is Python 3 I'm going to assume this is not a lesson. Moved to Corner Bar.


#21

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.