Word up exercise


#1

Hi, this code will not pass and the error message keeps asking if I created a variable called word - any clues on where I'm going wrong?

pyg = 'ay'

original = raw_input('Enter a word:')

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

else:
    print 'empty'

#2

I just realised i put : after and original.isalpha() I tried to remove it but it is still coming up with the same error message


#3

I don't see anywhere there where you have defined a variable called word.


#4

i just entered the following updated code but it's still wrong.. any clues on what I need to fix? Have i declared the variable wrong?

` pyg = 'ay'

original = raw_input('Enter a word:')
var = word

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

else:
print 'empty' `


#5

First of all, can you put your code inside the button that looks like this: <./>
It helps us read your code


#6

original = raw_input('Enter a word:')

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

else:
    print 'empty'

#7

is word == original.lower() not the declaration of the variable???


#8

It is not. You've used a comparison operator, == that means: "compare the thing on the left with the thing on the right and give the result, either True or False".

You should use the assignment operator = to assign a value to word.

I can help noticing several instances of the word and in places that are unexpected.


#9

okay, i just edited the code but it's still coming up as wrong.. :unamused: How come I shouldn't include and or should i only use it once?? i tried including or but that was wrong as well. I'm confused!!!

original = raw_input('Enter a word:')

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

else:
    print 'empty'

#10

It seems like you have the right idea, but there is still some things you need to work out.
Try starting the code with

pyg = 'ay'

Then deleting all the ors and putting original.isalpha(): on the same line as len(original) > 0 with an "and"

Hope this helps :slight_smile:


#11

You use and when you are checking for something, for example, "Is the length greater than zero?" AND "Does the word consist of only letters?"

You wouldn't use it to set the value of a variable.


#12

okay, I just revised my code and it is still asking to declare the variable.. i have a feeling that this is much easier than i have made it out to be.. I've been stuck for ages now!! :sweat:

original = raw_input('Enter a word:')

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

else:
    print 'empty'

#13

Don't forget to put a : after your if statement!
You don't need a : for first = "word"[0]:

These are just minor syntax errors.

Also make sure to print the first letter of the word with print first and not print (original)


#14

Thank you !!!! I finally got the right answer :slight_smile:


#15

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