Access by Index


#1



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.


#2

Can you provide a link to the exercise?


#3

https://www.codecademy.com/courses/python-beginner-sRXwR/0/4?curriculum_id=4f89dab3d788890003000096#


#4

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


#5

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:


#6

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


#7

Welcome. Glad to help. :slight_smile:


#8

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


#9

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


#10

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