-1

I have got a database program to keep data in, and I can't solve this problem:

I have got two functions. When you input A into the program the function called addy() starts and ask for more input into a variable then it returns to the main screen, then the user can Input S which starts Show() and then it's supposed to show what you have added into the variable

PROBLEM: It's not getting the value from the previous definition.

CODE:

def addy():
    os.system('cls')
    addel = input('what is the name of the operating system?: \n')
    os.system('cls')
    time.sleep(1)
    print(addel + ' Has been added to the database!')
    time.sleep(2)

    program()


def show():
    
    print('Heres a list of the operating systems you have added:')
    time.sleep(5)
    program()
    addel = addy()
    print(addel)  # this should print the value from the previous function
khelwood
  • 55,782
  • 14
  • 81
  • 108
tkinterpy
  • 13
  • 1
  • What is `program()`? – Mark Moretto Jul 22 '20 at 23:59
  • 1
    I'm pretty sure it is because you are not returning anything in the `addy()` function. Do you get `None`? – Julio Suriano Jul 23 '20 at 00:00
  • Oh, I actually managed to find a duplicate for this extremely common question that is phrased slightly differently every time. TODO: create a canonical version that is asked in the way that experienced programmers would ask, if they pretended not to know the answer. Not sure it's a particularly *good* duplicate, but I hope it's sufficient for OP. – Karl Knechtel Jul 23 '20 at 00:07
  • program() returns to the menu – tkinterpy Jul 23 '20 at 00:09

1 Answers1

0

The are 2 reasons why

  1. Addel is a local variable not a global one. Therefore, you can only use it in your addy function.
  2. Say your intent was not to use it which is what it seems, you wrote
addel = addy()

the function addy has no return value so your code wont work. to fix this write

return addel

as the last line in your addy function then it will work because now the function has a return value.