Reputation:
s: five - letter string
psn: an int between 0 and 4
return: result the character that is at position psn in s
def index_string(s,psn):
position = psn -1
return s[position]
I don't know what I am missing?
Upvotes: 0
Views: 71
Reputation: 1
You don't need the first line, as Python strings are indexed starting with 0:
def index_string(s, psn):
return s[psn]
s = index_string('March', 2)
print(s == 'r')
https://docs.python.org/reference/datamodel.html#emulating-container-types
Upvotes: 1