1

So, I'm making this program to help study for my Japanese class. As you may be able to see it shuffles a list of words and displays them. Then the program asks for a translation. It's supposed to check if the answer is correct or not and display the appropriate message. However, regardless of whether the answer is correct or not it will display all of the "incorrect" messages. My question is how to fix this issue. Please, I need help, and I would like to finish this before I take the next level of the Japanese class. Thank you to anyone who is willing to help me out a bit.

import random

words = ['ano', 'ima', 'eego', 'hai', 'gakusei', '...go', 'kookoo', 'gogo', 'gozen', '...sai', '...san', '...ji', '...jin', 'senkoo', 'sensei', 'soo desu', 'daigaku', 'denwa', 'tomodachi', 'namae', 'nan/nani', 'nihon', '...nensei', 'han', 'bangoo', 'ryuugakusei', 'watashi', 'amerika', 'igirisu', 'oosutoraria', 'kankoku', 'suweeden', 'chuugoku', 'kagaku', 'ajia kenkyuu', 'keizai', 'kokusaikankei', 'konpyuutaa', 'jinruigaku', 'seeji', 'bijinesu', 'bungaku', 'rekishi', 'shigoto', 'isha', 'kaishain', 'kookoosei', 'shufu', 'daigakuinsei', 'bengoshi', 'okaasan', 'otoosan', 'oneesan', 'oniisan', 'imooto', 'otooto']
random.shuffle(words)

index = 0
while index < len(words):
    print()
    print(words[index])
    translation = input('Enter the translation: ')
    index += 1
    print()

    if words == 'ano' and translation == 'um':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: um.')

    if words == 'ima' and translation == 'now':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: now.')

    if words == 'eego' and translation == 'english':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: english.')

    if words == 'hai' and translation == 'yes':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: yes.')

    if words == 'gakusei' and translation == 'student':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: student.')

    if words == '...go' and translation == 'language':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: language.')

    if words == 'kookoo' and translation == 'high school':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: high school.')

    if words == 'gogo' and translation == 'pm':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: pm.')

    if words == 'gozen' and translation == 'am':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: am.')

    if words == '...sai' and translation == 'years old':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: years old.')

    if words == '...san' and translation == 'mr/ms':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: mr/ms.')

    if words == 'ji' and translation == "o'clock":
        print('Correct!')
    else:
        print('Incorrect.')
        print("The correct answer is: o'clock.")

    if words == 'jin' and translation == 'people':
        print('Correct.!')
    else:
        print('Incorrect.')
        print('The correct answer is: people.')

    if words == 'senkoo' and translation == 'major':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: major.')

    if words == 'sensei' and translation == 'teacher':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: teacher.')

    if words == 'soo desu' and translation == "that's right":
        print('Correct!')
    else:
        print('Incorrect.')
        print("The correct answer is: that's right.")

    if words == 'daigaku' and translation == 'college/university':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: college/university.')

    if words == 'denwa' and translation == 'telephone':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: telephone.')

    if words == 'tomodachi' and translation == 'friend':
        print('Correct.!')
    else:
        print('Incorrect.')
        print('The correct answer is: friend.')

    if words == 'namae' and translation == 'name':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: name.')

    if words == 'nan/nani' and translation == 'what':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: what.')

    if words == 'nihon' and translation == 'japan':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: japan.')

    if words == '...nensei' and translation == 'year student':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: year student.')

    if words == 'han' and translation == 'half':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: half.')

    if words == 'bangoo' and translation == 'number':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: number.')

    if words == 'ryuugakusei' and translation == 'international student':
        print('Ccorect!')
    else:
        print('Incorrect.')
        print('The correct answer is: international student.')

    if words == 'watashi' and translation == 'I':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: I.')

    if words == 'amerika' and translation == 'america':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: america.')

    if words == 'igirisu' and translation == 'britain':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: britain.')

    if words == 'oosutoraria' and translation == 'australia':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: australia.')

    if words == 'kankoku' and translation == 'korea':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: korea.')

    if words == 'suweeden' and translation == 'sweeden':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: sweeden.')

    if words == 'chuugoku' and translation == 'china':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: china.')

    if words == 'kagaku' and translation == 'science':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: science.')

    if words == 'ajia kenkyuu' and translation == 'asian studies':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: asian studies.')

    if words == 'keizai' and translation == 'economics':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: economics.')

    if words == 'kokusaikankei' and translation == 'international relations':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: international relations.')

    if words == 'konpyuutaa' and translation == 'computer':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: computer.')

    if words == 'jinruigaku' and translation == 'anthropology':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: anthropology.')

    if words == 'seeji' and translation == 'politics':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: politics.')        

    if words == 'bijinesu' and translation == 'business':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: business.')

    if words == 'bungaku' and translation == 'literature':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: literature.')

    if words == 'rekishi' and translation == 'history':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: history.')

    if words == 'shigoto' and translation == 'job' or translation == 'work' or translation == 'occupation':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: "job" or "work" or "occupation".')

    if words == 'isha' and translation == 'doctor':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: doctor.')

    if words == 'kaishain' and translation == 'office worker':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: office worker.')

    if words == 'kookoosei' and translation == 'high school student' or translation == 'highschool student':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: "high school student" or "highschool student".')

    if words == 'shufu' and translation == 'house wife':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: house wife.')

    if words == 'daigakuinsei' and translation == 'graduate student':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: graduate student.')

    if words == 'daigakusei' and translation == 'college student':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: college student.')

    if words == 'bengoshi' and translation == 'lawyer':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: lawyer.')

    if words == 'okaasan' and translation == 'mother' or translation == 'mom':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: "mother or "mom".')

    if words == 'otoosan' and translation == 'father' or translation == 'dad':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: "father or "dad".')

    if words == 'oneesan' and translation == 'older sister' or translation == 'big sister':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: "older sister" or "big sister".')

    if words == 'oniisan' and translation == 'older brotehr' or translation == 'big brother':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: "older brother" or "big brother".')

    if words == 'imooto' and translation == 'younger sister' or translation == 'little sister':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: "younger sister" or "little sister".')

    if words == 'otooto' and translation == 'younger brother' or translation == 'little brother':
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: "younger brother" or "little brother".')
1
  • You should put the English and Japanese words as tuples in a list; i.e. separate the logic from the data. Only one (or a few) if-sentence(s) are then needed. Much less code, less error prone and easier to read... Commented Dec 3, 2012 at 22:07

3 Answers 3

4

There are several issues.

Firstly, you are comparing words instead of word[index] in

if words == 'ano' and translation == 'um':

and in other places.

Secondly, for the logic to work you'd need to restructure every if statement to prevent lots of Incorrect messages printed out for every input.

Rather that trying to fix this, I propose a more data-driven approach:

import random

dictionary = {'ano': 'um', 'ima': 'now', ...}
words = list(dictionary.items())
random.shuffle(words)

for word, translation in words:
    print(word)
    answer = input('Enter the translation: ')

    if answer == translation:
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: %s.' % translation)
Sign up to request clarification or add additional context in comments.

8 Comments

You should probably be more explicit about the removal of all the else clauses. It isn't obvious that you want them to be removed. Even once they are removed, the program still doesn't function as desired.
your edit shows that you are keeping the else clauses. Unless they are removed, or there are substantial changes to the program, every (except maybe one) 'Incorrect' message will still show.
I did a small test with only 2 words from the list and the program did the same thing, except when it ran across it's if statement (if I typed the right answer) it would say correct for the one and then continues to display the incorrect message for the rest.
I think the recent edit will work. I'm going to test it out right now.
Since you are using python 2 you don't need all those parentheses after your print statements. (If you meant to use python 3 then you need to replace raw_input() with input())
|
1

Just a suggestion, I would use a program like this instead of all of those if else clauses

import random

translations = {'ano': 'um', 'ima': 'now', 'eego': 'english'}

japanese = translations.keys()
random.shuffle(japanese)

for word in japanese:
    print word
    english = raw_input("Enter the translation: ")
    if english.lower() == translations[word]:
        print "Correct"
    else:
        print "Incorrect"
        print "The correct answer is %s" % translations[word]

1 Comment

Note: I used raw_input as I am on Python 2.7, so if you are on 3.x then input is right.
0

You should really use a dictionary, or atleast two lists for this.

words = {
    "word1": "answer1",
    "word2": "answer2",
    "word3": "answer3"
}
for word in words:
    answer = input("Translate '" + word + "':")
    if answer == words[word]:
        print("Correct!")
    else:
        print("Fail! Correct translation would be: " + words[word])

That might be somewhat wrong, I'm on a mobile and can't remember the syntax for dictionary iterating atm, you might have to convert it into a list of tuples first.

edit: While I was slowtyping with my phone, wild 50 answers appeared. Sorry for the extra answer :P

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.