0

I am trying to call and return a function made up of three other functions, any pointers?

def ForeName():
    forename = raw_input("Please enter you're Forename: ")
    return forename


def MiddleName():
    middle_name = raw_input("Pleaase enter you're Middle name: ")
    return middle_name

def SurName():
    surname = raw_input("Please eneter you're Surname: ")
    return surname

def UserName():
    result = UserName()
    print "result %s" % (result)

UserName()
6
  • 1
    Please, format your question. Especially, when it is about python... Commented Nov 14, 2016 at 20:31
  • sorry was a rushed post! Commented Nov 14, 2016 at 20:33
  • Thanks. Looks much better! Commented Nov 14, 2016 at 20:33
  • you're not calling the 3 name functions, include the parens Commented Nov 14, 2016 at 20:33
  • Um... don't call UserName() in the definition of UserName(), it don't work like that Commented Nov 14, 2016 at 20:47

2 Answers 2

1

Why do you have str parameters in every function? You don't use them, delete them so they don't clutter your code.

After doing that, you can call your methods only if you have () after their names, like this:

    result = ForeName(), MiddleName(), SurName()

You should set return value of a UserName(str) to something and then print that.

You probably want this:

result = UserName(str)
print "result %s" % (result)

(Or just UserName() if you delete the str parameter.)

Sign up to request clarification or add additional context in comments.

5 Comments

My guess is that he's confusing class vs. function definitions. With classes, you would put the return type there...
@ElliotRoberts: What do you mean, return type of a class?
Oop, this is 2.7; in 3.5, when defining a class, you put the parent class in the parentheses after class MyClass and this is usually the type that the class constructor returns.
I think I broke python :,) now it seems to just run the minute I launch it and keeps going until a runtime error occurs. crazy thing is there is no loop in it.
You still need parentheses after each function call... just like stated above: result = ForeName(), MiddleName(), SurName()
0

There is a lot of boilerplate code. You could write something that accepts the type of name you are looking for from the prompt.

def get_name(name_type):
    return raw_input('Please enter your {}name\n'.format(name_type))

def user_name():
    result = get_name('fore'), get_name('middle'), get_name('sur')
    return ' '.join(result)

print('Result: ' + user_name())

The result would look like this:

Please enter your forename
Darren
Please enter your middlename
Coder
Please enter your surname
Macis
Result: Darren Coder Macis

3 Comments

interesting way of doing it. I copied your code but left out the {} and it still worked. is it needed? ahh cancel that, I see it moves it from first to middle to sur. without it, it just repeats and lists forename three times
The {} is telling format where to put name_type similar to the % sign.
If you would prefer you could replace the input of raw_input with this: 'Please enter your %sname\n' % name_type

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.