0

why does this code print

Hello

None

None

def begin ():
    print("Type new to start a new game or load to load the previous game")
    print prompt_start()

def start ():
    print("hello")

def prompt_start ():
    prompt_0 = raw_input("Type  command:")
    if prompt_0==("new"):
        print start()
    elif prompt_0==("load"):
        load()
    else:
        print("read instructions!")
        print prompt_start

begin()

please give solutions to this as i can't figure out what is wrong

cricketts
  • 9
  • 1

2 Answers2

2

Because each function has an implicit return None, your prompt_start() function returns None. print prompt_starts() prints what the function call returns: None.

A relevant question that may help you.

Community
  • 1
  • 1
Celeo
  • 5,583
  • 8
  • 39
  • 41
1

This is because you functions prompt_start() and prompt_start() don't return anything. Thus, when you write print prompt_start(), Python evaluates your functions and then tries to print its results (which in your case is None, as it doesn't return anything).

Below is the code that doesn't print None:

def begin ():
    print("Type new to start a new game or load to load the previous game")
    prompt_start()

def start ():
    print("hello")

def prompt_start ():
    prompt_0 = raw_input("Type  command:")
    if prompt_0==("new"):
        print start()
    elif prompt_0==("load"):
        load()
    else:
        print("read instructions!")
        prompt_start() # <- missing parens  to call the function
begin()
syntagma
  • 23,346
  • 16
  • 78
  • 134