-1

i need to write a function changeName(name) that takes a string value as an argument. where name is in the form last,first,middle. the function should return a string that has the name in form fits,middle,last.

name1 = input("Enter your name")

def changeName(name):
fields = name.split(",")
return fields
fields = changeName(name1)
print(fields[1],fields[2],fields[0])

thanks what i did but it says it is out of range...

Votes + Comments
Still no [code] tags!
3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by vegaseat
0
name1 = input("Enter your name")

def changeName(name):
    fields = name.split(",")
    return fields
fields = changeName(name1)
print(fields[1],fields[2],fields[0])

I can not replicate the error, and please uset the code-tags! You did them, I see, but your code is not between them!

Enter your nameVeijalainen, Tony, Jarkko
 Tony  Jarkko Veijalainen

Edited by mike_2000_17: Fixed formatting

0

replicating the error is just to organizing the code or fix... dont know why you cant

0

The input has to be in the form last,first,middle. You got to let the user know ...

def changeName(name):
    """
    change name of form last,first,middle to first,middle,last
    """
    fields = name.split(",")
    return fields[1],fields[2],fields[0]

# input has to be in the form last,first,middle
test_name = 'Staub,Joe,P.'
new_name = changeName(test_name)

print(new_name)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.