Ending up


new = 'ay'
original = raw_input(" Enter a word")
word = original.lower()
first = "word"[0]
new_word = word + first + new
new_word = [1:len(new_word)]
if len(original) > 0 and original.isalpha() == True:
print new_word
print 'empty'

what is wrong with my code

Where is it going?


print "hello world"[0:6]

see how i specify the string i want to take a slice of before the square brackets? How else is python suppose to know, what it should take a slice from


What Stetim is saying is correct. At this line:
new_word = [1:len(new_word)]
You are not saying from what you are slicing.

Tells the console to take characters 2 until the amount of characters in new_word from...
It is not saying where to slice the characters from
Fixes this.

Also with first = "word"[0] you are saying take the first letter of the string "word" and not of the value of the variable word. So it will always be "w" in this case. If you remove the quotes you are telling it to take the variable instead of the actual string.

Hope this helps


2 posts were split to a new topic: Ending up


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