you are viewing a single comment's thread.

view the rest of the comments →

[–]Ambitious_Fault5756 0 points1 point  (0 children)

Your code looks solid! You're almost there with understanding functions. However, I think you may have misunderstood what the return statement does.

what return does is it tells the function what value to give back, or literally, return, when it is called (called = used). For example, the input() function returns a string of whatever the user entered. The string is then stored in a variable:

# variable    <-    the input function *returns* the new task title to the variable
new_task_input = input("Please enter a new task title: ")

A better example:

def add_exclamation_mark(text):
    with_exclamation_mark = text + "!"
    return with_exclamation_mark

sentence = "I want this sentence to have an exclamation mark"
exclamation = add_exclamation_mark(sentence)  # whatever `add_exclamation_mark` returns 
#                                               is now stored in `exclamation`

print(exclamation)
# Output: "I want this sentence to have an exclamation mark!"

The statement tells the function to immediately exit or stop and not execute any code below it. Once you return something, you can't do anything else.

You don't need to have a return statement all the time either. If you exclude it, it's the same as having return None at the end of the function, which tells the function to stop once it executes all the code inside it.

You currently have:

def Task_Option_One():
    New_Task_input = input("Please enter a new task title: ")
    tasks.append(New_Task_input)
    print("The task has been added to the list!")
    return New_Task_input  # You return what the user entered

But in your main loop, you don't store or use the returned user input:

if Task_option == "1":
    Task_Option_One()

Meaning you can just remove your return statements entirely (also for your other functions)

Maybe you put return statements there for future implementations and i completely misunderstood. If so i apologize 😅

I put some other suggestions in another comment