Dec-22-2018, 05:41 PM
Hey!
I am trying to do the following:
1/user inputs a name e.g. "John".
2/user gets returned with the last character of the string e.g. "n".
Where I am so far:
This does not work.
I get IndexError: string index out of range
However, this works (see line 3):
Any idea what I got wrong?
Thanks!
I am trying to do the following:
1/user inputs a name e.g. "John".
2/user gets returned with the last character of the string e.g. "n".
Where I am so far:
1 2 3 4 |
name = input ( "provide an example of name: " ) indexOfName = len (name) lastLetterofName = name[indexOfName] print (lastLetterofName) |
I get IndexError: string index out of range
However, this works (see line 3):
1 2 3 4 |
name = input ( "provide an example of name: " ) indexOfName = len (name) lastLetterofName = name[indexOfName - 1 ] print (lastLetterofName) |
Thanks!