-2
import sys

I cant check if this import works because the code itself doesn't work

options_list = [1,2,3]

def options(options_list):
    print ("\n1. Hypotenuse solver \n2. Scat jazz \n3. Exit")
    print ("Enter the number of the option you would like")
    option = input()
    return option

option = options(options_list)

while option not in options_list:
    option = options(options_list)

if option in options_list:
    if option == 1:
        print ("...")

I'll add this later, hopefully

    elif option == 2:
        print ("Scoobidibahbahbah")
    elif option == 3:
        sys.exit

this is for a school project, a hypotenuse solver with a menu

wwii
  • 23,232
  • 7
  • 37
  • 77
  • Please format the code - select it and type `ctrl-k`. .. [Formatting help](https://stackoverflow.com/help/formatting) ... [more Formatting](https://stackoverflow.com/editing-help) ... [Formatting sandbox](https://meta.stackexchange.com/questions/3122/formatting-sandbox) – wwii Feb 20 '20 at 19:06
  • 1
    Does this answer your question? [How can I read inputs as numbers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – wwii Feb 20 '20 at 19:19
  • 1
    Pasting your code into my editor results in the following warnings: _Shadows name 'options_list' from outer scope_, _Parameter 'options_list' value is not used_. – AMC Feb 20 '20 at 19:19
  • Presumably you wrote it that way. What is your problem, exactly? – vonbrand Feb 20 '20 at 21:25

1 Answers1

0

Try converting option to int before returning it from options method.

Instead of return option, try return int(option)

input() reads values as string. When you are comparing option==1, a string and integer are compared and there are no else statements which handles this scenario. Also the option that you have got is always not in options_list. That is why your code keeps on going on an infinite loop without printing anything.

The import works correctly because sys is a reliable python package.

MVG
  • 314
  • 1
  • 3
  • 17