Access by Index


String and Console Output Access by Index
I am not really sure what I am supposed to do here.

Oops, try again. Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: name 'Y' is not defined
Traceback (most recent call last):
File "python", line 13, in
NameError: name 'MONTY' is not defined

Not sure

Replace this line with your code.


Can you provide a link to the exercise?



I think I am a bit confused on what it is asking or how to write out the code.


Alright, I understand why you are confused, as this is a confusing concept to understand at first. :slight_smile: When we have a string, we can access certain parts of it like this:

#if we want the fourth letter from Tanini
print "TANINI"[3]

Now, as you can see, I accessed the third letter instead of the the fourth from the string. This is because the index(numbers) start from zero instead of 1, so the "T" in string above is actually number 0. What the exercise wants you to do is the exact same thing, but for the string "MONTY". It wants you to store the "Y" in "MONTY" under the variable "fifth_letter". Now try it, and if you need help then just message me again. :slight_smile:


Excellent thanks. I typed in "MONTY"[4] and it worked.


Welcome. Glad to help. :slight_smile:


Thanks this helped confirm I was on the right track. I actually sort of had it, but I was missing the "" around MONTY.


Welcome! Glad to help. :slight_smile: You get the concept though, right?


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.