8.Word Up python


#1

for some reason when I type my word in uppercase it stays uppercase even though it's suppose to go lower but it still lets me pass so I'm confused. example: Luke should become luke but stays the same.
here's my code:

pyg = 'ay'

original = raw_input('Enter a word:')

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

I've tried going on but then it wont work later on in the lesson so please help it would be much appreciated.


#2

This line may be removed once we start inserting code. The printing will take place in the last exercise.


#3

that doesn't help I'm trying to figure out why my code isn't changing the string to lower. e.g. Luke should become luke but is not.....


#4

You are not printing the lowercase version, but the original in the opening post code. For this lesson, given the above code, the only print out will be "empty" if the raw_input is a an empty string.


#5

I'm on ending up now, but it's driving me insane I just don't understand it, here's my code:
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
print new_word = [1:len(new_word)]

else:
print 'empty'

please help and also thank you for all the help you have already given me.


#6

also i can get it to work when I take the = out of inbetween the new_word and the [1:len(new_word)] but then the error message: Oops, try again.
It looks like you printed the correct translation of "sexy", but make sure to set new_word equal to the slice as well.
thanks- Seth


#7

Break this up...

new_word = new_word[1:len(new_word)]
print new_word

#8

I tried that but now the error message: Oops, try again. Your code did not run to end - see the console window for the error message.
File "python", line 12
new_word = [1:len(new_word)]
^
SyntaxError: invalid syntax

heres my code: 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)]
 print new_word

else:

print 'empty'

again thanks for your help.


#9

We need to apply the slice index to an object...

... = new_word[ ... ]

#10

now the error message: File "python", line 12
oringinal = new_word = [1:len(new_word)]
^
IndentationError: unindent does not match any outer indentation level
heres my code:

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

oringinal = new_word = [1:len(new_word)]
print new_word

else:

print 'empty'


#11

the ^ is pointing is meant to be pointing at the ]


#12

The pointer doesn't necessary point to the error, itself, just the place in the code where the interpreter stopped due to an exception previous to that point.

At this point in the exercise, we no longer need to print original so that line may be removed. With that gone, the next three lines of code are correct, but this line,

is a bit off. Rewrite it like so...

new_word = new_word[1:len(new_word)]

Be sure that line and the following print statement have the same indentation as the previous three lines (all in the if statement. Your else will line up with if, and print empty will be indented.


#13

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