"Ending Up" PLZ HELP ME!


#1


https://www.codecademy.com/courses/python-beginner-2W5v7/1/4?curriculum_id=4f89dab3d788890003000096#

Oops, try again. It looks like new_word contains "whatway" instead of "hatway"!


Replace this line with your code.  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:]


#2

Hey netanemo,

I took the liberty to alter your code a tad bit, see below including the explanation.

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

word = original.lower()
first = word[0]
new_word = word[1:] + first + pyg

if len(original) > 0 and original.isalpha():
print new_word

else:
print 'empty'

I personally like all the variables at the top, but you can do it however you please this just makes it easier for me. So first I got rid of new_word[1:] since we can just do new_word = word[1:] + first + pyg and it will do the exact same thing. Also notice I set print to new_word instead of original because you are wanting to print the final product not the original. That is pretty much all I changed you can do this multiple ways, but this way works best for me. I hope I helped you out if anything reply here.


#3

Thank you bro. I had no idea you could do it that way. im a beginner :expressionless:


#6

is showing error in the line word = original.lower()
pyg = 'say'

original = raw_input('Enter a word:')

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

print new_word

else:
print 'empty'
its showing error in the line no 5? pls help me out! Advance thank you :slight_smile:


#7

yeah resolved the error :D

#8

@siddhee, please give us the code you used to resolve it. :slight_smile:


#9

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 = new_word[1:len(new_word)]
print new_word
else:
print 'empty'
# This will help !


#10

why is my code only working when i take out the

"else:
print 'empty'"

it says its an invalid syntax and that the code didnt run all the way through whenever I leave that in at the end but when i take it out it works right away?? this doesnt make any sense


#11

here is my full code that worked :
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 = new_word[1:len(new_word)]
print new_word

and if i add the "else:print empty" part, it doesnt work for some reason? makes zero sense please help


#12

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