Comparing word from raw_input to wanted string


#1

Hi there,
I am trying to make a program that asks someone to translate a certain word from a foreign language to English.
I ask them using raw_input for a translation and then want to compare each the letters from the word they inputted to the correct way of spelling. For example:

q = raw_input ("How do you spell in English the Danish word x")
  first_letter = q [0]
  second_letter = q [1]
  thrid _letter = q [2]
if first_letter.lower() == "d" and second_letter.lower() == "o" and third_letter.lower() == "g"
    print "Right on!"

As you can see I am trying to compare each letter of the answer that was inputted to the correct way of spelling.
Am I doing this right at all? I know you can just import a library of spelling check but I need it this way.
Thanks


#2

You can compare two string together. Say I have
q = raw_input("") // say the user inputted “dog”
correctWord = “dog”

I can use q == correctWord to check if the the user inputted the right word


#3

But what if I want to do it the way I presented?
What I am doing wrong?


#4

is this your code:

q = raw_input ("How do you spell in English the Danish word x")
  first_letter = q [0]
  second_letter = q [1]
  thrid _letter = q [2]
if first_letter.lower() == "d" and second_letter.lower() == "o" and third_letter.lower() == "g"
    print "Right on!"

that should give an indent error.


#5

For starters, the index block should be married to the name…

q[0]

No whitespace.

Second, since the return from raw_input is a string, we can slice it…

if q[:3] == 'dog':