1.11M Members

Help making a Japanese study program

 
0
 

The program I'm making is a program that will display a word in one language and ask for the translation in another. It will then display if it's right or wrong. However, when I test to see if it works, it will display all of the versions of Incorrect, even if the answer is correct. How do I get it to only display the appropriate message? Such as if somethings correct say ('Correct!') and if somethings wrong say ('Incorrect. The correct answer is _')

This is what I have:

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(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.')



   (etc..this pattern continues until all words are used)
 
1
 

First, use a dictionary or list of lists to hold the question and answers instead of 100 if statements. I assume you don't know about dictionaries yet so this uses a list of lists.

words = [['ano', 'um'], ['ima', 'now'], ['eego', 'english']]
random.shuffle(words)
for this_question, this_answer in words:
    print (this_question)
    translation = input('Enter the translation: ')
    if translation == this_answer:
        print('Correct!')
    else:
        print('Incorrect.')
        print('The correct answer is: '+this_answer)

    print("-"*30)

To answer your original question, learn to use print statements for simple debugging

print("comparing", words, "with ano =", translation)
if words == 'ano' and translation == 'um':
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: