-4

In my python program, there are functions within functions, and I've noticed that there are varying amounts of line between where the previous function ends and the first function starts.

Output:

end of previous function


start of first function

However, when the return() statement isn't used, "None" is printed at the end of the function.

Is there any way to get the program to only print out one line after the end of a function, or is this an unavoidable part of python?

(may be related to this, but you can't use this for return I don't think)

Example code:

def function1():
    ...stuff

def function2():
    function1()
    ....morestuff

while True:
    function2()

This will return 2 lines of "None". If return("") is added to the end of each function, just white space is there, and so are the new lines. Is there a way to have a certain amount of lines, or to get rid of them altogether?

ACTUAL CODE EXAMPLE:

def stop():
    print("stop")

def login():
    print("login")

def list():
    print("list")

def runscript():
    answer=raw_input("input")
    if answer == "stop":
        print(stop())
    elif answer == "login":
        print(login())
    elif answer == "list":
        print(list())

while True:
    print(runscript())

This returns "None" as well as the designated output. If a return("") is added to the end of each function, it still outputs different lines

Community
  • 1
  • 1
L0neGamer
  • 275
  • 3
  • 13

1 Answers1

1

You are getting None because of the print statements in runscript. Remove them:

def runscript():
    answer=raw_input("input")
    if answer == "stop":
        stop()
    elif answer == "login":
        login()
    elif answer == "list":
        list()

btw, you probably want to add a space after input: raw_input("input ")

Vidhya G
  • 2,250
  • 1
  • 25
  • 28