pyLatin


#1

pyg = 'ay'

original = raw_input('Enter a word:')

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

what's error in this code please ?


#2

Instead of ...

print [1:len(new_word)]

... assign that slice to new_word, then ...

print new_word

EDIT: See @stetim94's advice. When taking a slice, you must specify the object from which the slice will be taken, prior to the square brackets. In this case, the slice needs to be taken from from new_word.


#3

ending up?

when taking a slice, you need to specify the variable you take a slice of:

x = "hello world"
print x[0:5]

see i how specify the variable i want a slice of before the the square brackets? after my suggestion, apply appylpye suggestion


#5

Can someone please post the correct code? I have been on this for hours and i have to finish python for school


#6

The best strategy for getting help is to post your code in its current state. Then other users can make specific suggestions. Remember to format any code that you post.

See How do I format code in my posts?.


#7

Thank you to your answers kbsa


#8

After the addition of variables:
new_word = word + first + pyg
you going to the new line and you have to assign variable new_word to new_word with the slice [1:len(new_word)] from the instructions like that:

new_word = new_word[1:len(new_word)]

EDIT: You doing it after addition, because variable new_word is not declared yet :confounded: so how can you take second letter to the end from it if you don`t know what the word is .

My code was like that beneath and passed - see? - you reassigning your variable with the slice:

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

But the 100% correct one, should be like that I suppose(passed too):

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

I just started, maybe I`m wrong with something, but my pleasure if I helped.


#9

pyg = 'ay'

original = raw_input('Enter a word:')

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

guys please, I have tried everything I don't know what to do anymore.
it keeps returning the error "Oops, try again. Did you accidentally delete the first variable?"
what did I do wrong?


#10

first_letter should be first (no choice in variable names)

this:

    original = original.lower()
    word = original

should could be one line of code

here:

new_word = word[1:len(new_word)]

take a slice of new_word, not word. then on the next line, print new_word


#11

Thank you, it worked:grin:


#12