10. Ending up Pyg lating


#1

TASK: 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

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)]
else:
print ‘empty’

i dont know whats wrong with my code i literally did what they told me


#2

what you attempt here:

[1:len(new_word)]

is named string slicing (or list slicing, depending on the data type)

which has the following general syntax:

"string"[start:stop]

you forgot to specify the string which python needs to slice. How else does python know what to slice?


#3

new_word= new_word[1:len(new_word)] ok i added new_word…the code in console doesnt seem to give output put the excersies seems to be marked with a check like its finished but the codes doesnt work…

EDIT: nvm i forgot to put print new_word

THANK YOU


#4

It doesn’t work is always a vague description :wink: It could be many things

If you want output, a print statement is certainly very useful. Good you figured it out :slight_smile:


#5

thanks brotha…jsut staretd learning python and its ■■■■■■■ frustrating…good to have u u already helped me once in the past


#6

Programming is very frustrating indeed. I would say it gets a little bit less frustrating, which is true, but the frustration will never go away completely. I recently was frustrated after spending 2 hours on a bug which turned out to be a single space too many :frowning:

i did, i forgot (for that i help to many people), but then i can look in your activity feed, and read the topic, and then i remember.

I can highly recommend you to read this topic:

How do I format code in my posts?

because without format, indent doesn’t show, look:

no indent in your code, if there is then an indent issues, its really difficult for someone helping you to find it.


#7

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