Reputation: 9
I'm stumped. I looked through my code a bunch of times and can't find out why I'm getting an invalid syntax for this bit of code. Any help would be greatly appreciated! Thanks.
def nameReverse():
name = str(input("Enter your full name: "))
testName = name.split()
if len(testName)>1:
firstName=testName[0]
lastName=testName[1]
print (lastName,firstName)
def main():
nameReverse()
main()
Upvotes: -1
Views: 5894
Reputation: 3874
The only error I got was an indentation error. This is python, so indentation is critical. Your if
statement was improperly indented. Here is what you want:
def nameReverse():
name = str(input("Enter your full name: "))
testName = name.split()
if len(testName)>1:
firstName=testName[0]
lastName=testName[1]
print (lastName,firstName)
def main():
nameReverse()
main()
Upvotes: 1
Reputation: 2468
If it is python 2.x you should use
name = str(raw_input("Enter your full name: "))
Full code:
def nameReverse():
name = str(raw_input("Enter your full name: "))
testName = name.split()
if len(testName)>1:
firstName=testName[0]
lastName=testName[1]
print (lastName,firstName)
def main():
nameReverse()
main()
Upvotes: 1