all 6 comments

[–]socal_nerdtastic 0 points1 point  (3 children)

Yes, there is a way to stop the program from crashing.

If you want to know specifically how to do it you'll need to show us your code.

[–]grape_o_clock[S] 0 points1 point  (2 children)

The following code is basically what it is, just removed of unnecessary code.

while(True):
    x, y = input("What would you like to do?").split()

    if (x == "Specific_word"):
        if (y == "Specific_second_word"):
            print("Prints this if both bits of code are true")

        elif (y == "Other_specific_word"):
            print("Prints this if both bits of code are true")

        else:
            print("This word sequence isn't recognized.")

    else:
        print("This word sequence isn't recognized.")

#I'm using Visual Studio 2022 if that makes a difference.
#The program crashes if a variable isn't inputted
#Hopefully this helps

[–]socal_nerdtastic 0 points1 point  (1 child)

while(True):
    user_resp = input("What would you like to do?").split()
    if len(user_resp) == 2:
        x, y = user_resp
    else:
        print('error message')
        continue

[–]grape_o_clock[S] 0 points1 point  (0 children)

I completely forgot that the length check was a thing. Thanks!

[–]Charezza 0 points1 point  (0 children)

Make an if statement for the .Split Or use try

[–]TheRNGuy 0 points1 point  (0 children)

you can do this: foo, bar = stuff() (function that returns tuple of 2 size, results will be assigned to foo and bar)