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
#2
It will be easier to read your code on this forum if you use /python tags as described here: BBCode

Your function menu() is going to return either an integer value or None if the input is invalid. You could assign this value to a variable and then pass it to started(), or you could pass it directly:

# Assign the value returned by menu() to a variable and then call started()
op = menu()
started(op)

# Pass the value returned by menu() directly
started(menu())
Also, to simplify your code in the menu function, you can do just a single comparison to determine if the input is what you expect before returning. (Note that your current code would throw an error if the user enters a non-integer value, by the way.)

if 1 <= option <=5:
    return option
else:
    print("Invalid selection")
    return
Reply


Messages In This Thread

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Functions and if elif problem Bruizeh 2 3,802 Aug-27-2021, 03:37 AM
Last Post: naughtyCat
  simple function problem stereokim123 5 3,319 Aug-26-2021, 04:44 PM
Last Post: naughtyCat
  I have a simple problem ahmed 5 2,557 Jul-17-2021, 02:50 PM
Last Post: ahmed
  Functions returns content of dictionary as sorted list kyletremblay15 1 2,071 Nov-21-2019, 10:06 PM
Last Post: ichabod801
  Problem with a simple script Niko047 2 3,353 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