Python Simple program (functions) problem HELP PLEASE

Hello guys I hope You will be able to help me with these simple functions. I can not understand and tried everything. My main problem is I don’t know how to pass the option choose from the first function main() to the started(operation), and I don’t know how I should use the operator in the other function. I will add some instructions to the code so everyone can understand what I am talking about. Thank You in advance guys.

def menu():
    Task 2: Display a menu of options and read the user's response.

    A menu consisting of the following options should be displayed:
    'Load Data', 'Process Data', 'Visualise Data', 'Save Data' and 'Exit'

    The user's response should be read in and returned as an integer corresponding to the selected option.
    For example, 1 for 'Load Data', 2 for 'Process Data' and so on.

    If the user enters a invalid option then a suitable error message should be displayed and the value
    None should be returned.

    :return: None if invalid selection otherwise an integer corresponding to a valid selection
    # TODO: Your code here
    print("\nWhat would You like to do ?")
    print(" \n 1- Load Data\n 2- Process Data\n 3- Visualise Data\n 4- Save Data\n 5- Exit  ")
    option = int(input())
    if option == 1:
        return option
    if option == 2:
        return option
    if option == 3:
        return option
    if option == 4:
        return option
    if option == 5:
        return option
        print("Invalid selection")

def started(operation):
    Task 3: Display a message to indicate that an operation has started.

    The function should display a message in the following format:
    '{operation} has started.'
    Where {operation} is the value of the parameter passed to this function

    :param operation: A string indicating the operation being started
    :return: Does not return anything
    # TODO: Your code here
    operation =
    if operation == 1:
        print("Loading has started")


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Thank You for doing that

The way you have started() currently defined, it requires an argument to run.
You want to pass option as an argument to start() and you can do that by storing the result of menu() as a variable and using that as an argument, or by passing menu() as an argument directly.

Make sure you have clearly defined for yourself what your functions can handle as input, and what they return as output.

You will want to clarify in the else-clause of menu() that it returns a None type, if that’s what the function is supposed to do. None is a key word in Python.

For a start, you cannot call main(), if you called the function menu().
Then menu() returns a number. What are you doing with that number? Nothing.
What are you doing with the number “option”? Save it to a variable - maybe that might be useful.
Keep in mind every variable you define within a function is local - meaning it only exists within the function and is deleted once the function ends. So “option” in menu() cannot be called from anywhere other than within menu().

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