Help :( Ending UP :(


#1

pyg = 'ay'
original = raw_input("Enter a word:")

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

else:
print('empty')

and it says: It looks like new_word contains "ma" instead of "arkmay"!

Pls. help me :frowning:


#2

The second time you declare new_word you are only telling it to get the first two letters from the last declaration of new_word.


#3

I've marked where you made mistakes.

You have also add one extra line of code .

More hints**
print (original.lower())
Is unnecessary but if you're testing then ok.

new_word = new_word[0:2]

You're slicing string wrong way..

refer to instruction...

Set new_word equal to the slice from the 1st index all the way to the end of new_word. Use [1:len(new_word)] to do this.

Ring a bell ?

at last don't forget to print the new_word


#4

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
new_word = [1:len(new_word)]

when I do this I get the error message:
Oops, try again. Your code did not run to end - see the console window for the error message.

File "python", line 13
new_word = [1:len(new_word)]
........................^ (dots there to show placement of "^")
SyntaxError: invalid syntax

I am not sure what I am doing incorrectly. I thought I was following the instructions


#5

@mumbet
here is a small mistake..
new_word = [1:len(new_word)]

When we slice something, we put that thing outside and Square bracket part after it.

#suppose if I had to slice this..

x = 'Python'

#I have to slice x..
#I will write..
x[1:3]

Do you get the hint?


#6

I'm still not getting this.

I don't understand how to slice.

My code is the same as above, I think:

pyg = 'ay'

original = raw_input('Enter a word:')

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


#7

Here's a link that may help you understand how to slice better. Hope this helps. :slight_smile:http://stackoverflow.com/questions/509211/explain-pythons-slice-notation


#8

Thanks so much. The slicing instructions was really the part I wasn't getting here.


#9

You're welcome! :smiley:


#10

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