Ending up "equal to the slice?"


#1

Hi guys, I've searched a TON of Q&A forums and made sure everything is in order, but it still displays the "you need to set new_word equal to the slice"

pyg = 'ay'

original = raw_input('Enter a word:')

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

I don't know what is wrong with this code, the new_word slices are basically identical and yet the error message persists...


#2

Your code is fine but it's just missing one fundamental component and that is adding first and pyg to your list slice,

new_word = word[1:len(new_word)]

add,

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


#3

hi guys, i still have a basic question, im not sure what the len() method does, can u clear my mind a bit please. :slight_smile: thnks


#4

The len() keyword, returns the length (number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).


#5

read that before, but still not clear.. xD. thanks


#6

Let me give you an example so you can understand practically,

If I have a string,

my_name = "Dave"

and a list,

my_name = ['Dave', 'Dave', 'Dave', 'Dave']
.

these two will both return the integer 4 because in my string,
.

my_name = "Dave" There four letters

and in my list,

my_name = ['Dave', 'Dave', 'Dave', 'Dave'] There four items

So basically the len() method returns the number of items in a valid data type. :slight_smile:


#7

peeerfect, that's what i needed a very simple example to understand it, thank uuuu so much!:slight_smile:


#8

No problem :slight_smile:


#9

Hi, so I have been trying to complete 'ending up' but it keeps saying that I got the wrong code:

def pyglatin():
pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    word = original.lower()
    first = word[0]
    new_word = word[1:] + first + pyg
    print new_word
else:
    print 'empty'
quest = raw_input("Want another word? Type yes or no!")
if quest =="yes":
    pyglatin()
else:
    print ("Bye!")
    return

pyglatin()

I did add in my own personalized code but I don't think it's the problem. Please clarify what is wrong please? Thank you!


#10

I have found the problem never mind. :slight_smile:


#12

Hi Bandit, thanks for the reply, I've added the first and pyg but the error message persists...

The code works well, though admittedly I don't understand what setting "new_word equal to the slices" because both slices are word[1:len(new_word)]... or am i missing something??


#13

Store your list slice in a same name variable new_word


#14

new_word = word[1:len(new_word)]

new_word = new_word + first + pyg

print new_word


#15

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