#Unclear about Homework Directions/Whether or not the code matches the instructions.

10 messages · Page 1 of 1 (latest)

devout fable
#

It's been some time but time for another question again. I'm confused about what it means by "token at index 0 is the word quit" I have programmed some of it but I'm not certain about that line so I don't know where to start off. I know I'm getting a type error because the bracket [] has an index of 0 with str which I don't think it correct since that would result in a type error.

Terminate Function:

    user = input("Are you sure you want to quit? (Y/y): ")
    if user == "Y" or user == "y":
        return True
    else:
        return False```
Main Function: 

```def main(str):
    command = input()
    while len(command):
        command.split()
        index = str[0]
        if "quit" == command & "quit" == index:
            if terminate(): #don't repeat functions
                print("Goodbye!")
            try:
                if command == "":
                    break
            except:
                print("Enter a command or 'quit' to quit")

main()```

The homework instructions are given for context. Thank you for your time 😄 Of course it's a programming class in college so I'm not going to be given enough time to complete it so I'm asking questions to understand the concept of the problem better.
iron dove
devout fable
#

Wait so if the user enters "quit" then call terminate function? I don't think my code matches that then

devout fable
devout fable
#
    command = input(">>")
    command.split()
    while len(command):
        if "quit" == command:
            print("Goodbye!")
            terminate() #don't repeat functions
            try:
                if command == "":
                    break
            except:
                print("Enter a command or 'quit' to quit")

main()``` I updated my main function now I'm not getting an error and when I type the word "quit" which leads to "goodbye" then it leads to "are you sure you want to quit Y/y" so I type y but it continues to ask the same question "are you sure you want to quit Y/y"
#

It doesn't match my desired output since I need it to be >> quit "are you sure you want to quit Y/y" then print "goodbye"

#
Goodbye!
Are you sure you want to quit? (Y/y): y
Goodbye!
Are you sure you want to quit? (Y/y):``` The current output
devout fable
#

I managed to fix my output but for some reason my try and except isn't working when I press enter which is an empty string it still prints "goodbye" but I want it to print ""Enter a command or 'quit' to quit"

#
    command = input(">>")
    command.split()
    while terminate_function:
        if "quit" == command:
            terminate()
            print("Goodbye!")
        else:
            pass
            try:
                if command == "":
                    break
            except:
                print("Enter a command or 'quit' to quit")

main()``` I updated my code and terminate function is a global variable that returns the boolean True which is at the very top of the file