8. Word Up


#1


To me it makes sense that it should work. apparently i'm wrong.

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

Enter a word: ayyebitch
Traceback (most recent call last):
File "python", line 4, in
TypeError: 'builtin_function_or_method' object has no attribute 'getitem'

Oops, try again. Did you create a variable called first?

original = raw_input('Enter a word:')
pyg = 'ay'
word = original.lower
first = word[0]

print word

if len(original) > 0 and original.isalpha():
    print original
else:
    print 'empty'

#2

The instructions state:

Inside your if statement:

01. Create a new variable called word that holds the .lower()-case conversion of original.
...

Therefore, you need to put your word variable and first variable inside your if statement.

Also please refrain from including profanities in your posts. Pointing at


#3

I thought that it just had to be a global variable?
I understand what you are saying but why does it have to be in the statement if it just needs to be able to call it?


#4

I just tried it your way and it doesn't seem to like my variable

original = raw_input('Enter a word:')

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

print word
print first

else:
print 'empty'

Enter a word: nicholas
nicholas
Traceback (most recent call last):
File "python", line 8, in
TypeError: 'builtin_function_or_method' object has no attribute 'getitem'

Oops, try again. Did you create a variable called first?


#5

it's word = original.lower(), not word = original.lower. It's a built-in function.
Also, instructions didn't say to move pyg into the if statement.

As for your global variables question, your if statement validates whether the input is valid. And then you need to do something.

What if your input is not valid? You still have to lowercase the input and take the first letter before printing empty if you put your variables outside. That's just redundant extra work. Also you get errors because global variables are implemented in a different way.


#6

I cannot believe i missed that....


#7

original = raw_input('Enter a word:')

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

print word
print first
else
print empty

Oops, try again. Did you create a variable called word?
File "python", line 4
print 'original'
^
IndentationError: expected an indented bloc


#8

It's as the error says, you need to indent your variable original. Make sure everything inside the if statement and else statement are indented properly.


#9

pyg = 'ay'

original = raw_input('Enter a word:')

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


#10

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'


#11

you have to put the original.lower() inside your if statement


#12

I finally got it to work.


#13

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