Confusion on PygLatin (literally please help me)


#1



https://www.codecademy.com/courses/python-beginner-2W5v7/1/4?curriculum_id=4f89dab3d788890003000096#


SOOOo I do NOT understand this exercise and I've been stuck on it forEVER. Every time i try to run it I just get an error :sweat: :cry:


 pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    print original
else:
    print 'empty'
word = original.lower()
first = word[0]
new_word = [1:len(new_word)] + first + pyg


what am i supposed to doooo???


#2

ignoring the logic of your program for a moment, you have to take a couple of syntax problems, in this line:

new_word = [1:len(new_word)] + first + pyg

You can take slices with [], but you have to specify the variable you want the slice of:

example = "hello world"
print example[0:5] # should print hello

see how i use variable name + [] to take a slice of a string stored in a variable? See if you can apply this logic to your problem

then the problem is with the slice self:

[1:len(new_word)]

you can't use variable with you haven't defined yet, you are defining new_word in this line, you can't use it yet, which variable contains the entire string entered by the user? Maybe you should use that one instead?

If you need more help, post an updated version of your code


#3

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    print original
else:
    print 'empty'
word = original.lower()
first = word[0]
new_word = word + first + pyg
print new_word[1:len(new_word)]

okay so this is my NEW code but now what it's saying is "It looks like you printed the correct translation of "stupid", but make sure to set new_word equal to the slice as well." and i have NO idea what that is supposed to mean...


#5

Well, things are going well until new_word. What you need to do is:

meaning that you need to set new_word equal to something that doesn't have it in it, being word[1:len(new_word)]. That would be the end of defining that variable and on the next line, you would want to use the += operator to overwrite new_word and add first + pyg to it. Then you should simply be able to print new_word.
Don't be afraid to try new things! Sometimes resetting your code helps so that you have a fresh start or even just trying things you think might not work.
I hope this helps!

EDIT:

mtf is right! This all needs to be inside of your if statement, I wasn't even looking at the way your code is written presently. I shouldn't have overlooked that, whoops.


#6

This entire segment of code should be in place of,

    print original

Then change this line to,

new_word = new_word[1:len(new_word)]
print new_word

As slicing goes, the author clearly wanted us to see the use of our object length as an index. The basic syntax will implicitly assume this value without our specifying it.

new_word[1:]

describes the exact same slice. The example given in the lesson is a very valuable piece of information to 'see' in this form so we know what to expect. Be sure to study up on string and list slicing in your reading time. It's a very important concept to be comfortable with going forward.


#7

I have no idea either... stuck on the 1st line. Help pls


#8

if you have a question, please make a new topic, use the template to provide us with the necessary information so we can help you


#9

I had the exact same issue as the poster(agriggs11). This line change example was the solution.


#10

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