Python Forum
Simple problem with functions and returns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple problem with functions and returns
#1
Hello guys I hope You will be able to help me with these simple functions. I can not understand and I tried everything.I spent couple days, watched videos etc. My main problem is I don’t know how to pass the choice from "option" frrom 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. Please for understanding.

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: My code
    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
    else:
        print("Invalid selection")
        return





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: My code here
    operation =
    if operation == 1:
        print("Loading has started")
menu()
started()
buran write Mar-17-2021, 01:59 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
Simple problem with functions and returns - by danlopek14q - Mar-17-2021, 10:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Functions and if elif problem Bruizeh 2 3,786 Aug-27-2021, 03:37 AM
Last Post: naughtyCat
  simple function problem stereokim123 5 3,300 Aug-26-2021, 04:44 PM
Last Post: naughtyCat
  I have a simple problem ahmed 5 2,551 Jul-17-2021, 02:50 PM
Last Post: ahmed
  Functions returns content of dictionary as sorted list kyletremblay15 1 2,066 Nov-21-2019, 10:06 PM
Last Post: ichabod801
  Problem with a simple script Niko047 2 3,345 Jul-21-2017, 09:02 PM
Last Post: Niko047

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020