Skip to content Skip to sidebar Skip to footer

"none" Keeps Showing Up When I Run My Program

Whenever I run the calculator program I created, it works fine but the text 'None' keeps showing up and I don't know why. Here's the code: def add(): print 'choose 2 numbers to

Solution 1:

That's because the function menu() is not returning anything, by default a function in python returns None

>>>deffunc():pass>>>print func()  #use `print` only if you want to print the returned value
None

Just use:

menu() #no need of print as you're already printing inside the function body.

New version of sys() after removing return menu() from add() and sub(). Instead of using return menu() inside each function simply call the menu() function at the end of while loop itself.

defsys():
    whileTrue:
        a = input("please choose")
        if a == 1:
            add()    # call add(), no need of print as you're printing inside add() itselfelif a==2: 
            sub()  
        menu()       # call menu() at the end of the loop

while loop==2 actually evaluates loop==2 expression first and if it is True then the while loop continues else breaks instantly. In your case as you're not changing the value of loop variable so you can simply use while True.

>>>loop = 2>>>loop == 2
True

Related : a basic question about "while true"

Post a Comment for ""none" Keeps Showing Up When I Run My Program"