Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple mistake about for
#1
Hello , sorry for this simple mistake but I could not solve this. I am trying to text firstly english then turkısh words.Then they will come random and if I know correct ,correctWords will increase. I have simple mistake that ı can not see, So pls can u show me where I did mistake.
import random
list_words = []
turkısh_words= []
def writeWords():
    print('Welcome to your english program.. To exit please write "exit"\n')
    while True:
        words = input('Your English word: ')
        if words == 'exit':
            break
        else:
            if words == "stop":
                print(list_words)
                break
            else:
                list_words.append(words)
                while True:
                    answers = input('Your Turkısh word: ')
                    turkısh_words.append(answers)
                    break
    print(turkısh_words)
    print(f'number of total words is {len(list_words)}')




            
def getWords():
    writeWords()
    wrong_Words = []
    correctWords = 0
    print("Words are coming...\n")
    for i in range(1,len(turkısh_words)+l):    
        get = random.choice(list_words)
        print(get)
        answer = input("Answer: ")
        if get == answer:
            correctWords += 1
        else:
            wrong_Words.append(get)
    print(f'Number of correct answers: {correctWords}')
    print(wrong_Words)
            
getWords()
I have a mistake about for probably. I do not know what to do , Help me pls.
Thank you.
Reply
#2
There is no reason to follow break; with else. Break takes you out of the loop. All remaining code in the loop is inside an implicit else.
def writeWords():
    print('Welcome to your english program.. To exit please write "exit"\n')
    while True:
        words = input('Your English word: ')
        if words in ('exit', 'stop'):
            break
        list_words.append(words)
        answers = input('Your Turkısh word: ')
        turkısh_words.append(answers)

    print(list_words)
    print(turkısh_words)
    print(f'number of total words is {len(list_words)}')
I can't see your mistake either. I type words and it keeps prompting me for more words. When I enter 'stop" it prints a list of words and I get an error for line 28. Is that the error? Is it the error that is caused by thinking lowercase L is a one?

Or is the error that getWords doesn't do what you want? I kind of expected a quiz. The computer prints a random word and I am supposed to enter t he translation. Instead the code tells me the answer is correct if I type in the word that is displayed. Is that the error?

All code longer than a few dozen lines is riddled with errors. This is especially true when you are learning how to program. Next time you have a question, please ask the question and provide as much detail as you can.
Reply
#3
In fact there is no error but I could not make a good 'for loop'.
I wanted to make = English word = yes, then Turkısh word = evet, When 'yes' will come random, when I will write 'evet'(in english 'yes') correctWords will increase.
But there is a problem here
writeWords()
    wrong_Words = []
    correctWords = 0
    print("Words are coming...\n")
    for i in range(1,len(turkısh_words)+l):    
        get = random.choice(list_words)
        print(get)
        answer = input("Answer: ")
        if get == answer:
            correctWords += 1
        else:
            wrong_Words.append(get)
    print(f'Number of correct answers: {correctWords}')
    print(wrong_Words)
When I answers like this,
yes = evet , it should be correct. Correct answer but, if I write this, it's being wrong. I mean if I wrote, yes = yes , it accepts it's true. But I wanted, yes = evet.
Sorry probably I did not tell well.

I will write in english then turkısh, when ı will answer in turkısh ; it will be correct but I could not do it.
Reply
#4
This becomes an easy problem when you make a two direction translation dictionary. For each pair of words, add a Turkish to English entry and an English to Turkish entry. Then you can randomly select a key from the dictionary and ask for the translation.
import random

translator = {}
turkish = []
english = []

def enter_translation():
    print('Welcome to your english program.. To exit please write "exit"\n')
    while True:
        a = input('Your English word: ')
        if a in ('exit', 'stop'):
            break
        b = input('Your Turkısh word: ')
        english.append(a)  # Don't need these lists
        turkish.append(b)
        translator[a] = b
        translator[b] = a

def turkish_translation():
    # To test English -> Turkish
    correct = 0
    random.shuffle(english)
    for word in english:
        answer = input(word + ': ')
        if answer == translator[word]:
            correct += 1
            print("Correct!")
    return correct

def turkish_translation():
    # To test Turkish -> English
    correct = 0
    random.shuffle(turkish)
    for word in turkish:
        answer = input(word + ': ')
        if answer == translator[word]:
            correct += 1
            print("Correct!")
    return correct

def mixed_test():
    # Randomly mix English and Turkish words
    correct = 0
    words = list(translator.keys())
    random.shuffle(words)
    for word in words:
        answer = input(word + ': ')
        if answer == translator[word]:
            correct += 1
            print("Correct!")
    return correct

enter_translation()
print ("You got ", mixed_test(), "correct")
Reply
#5
(Jul-16-2020, 02:21 AM)deanhystad Wrote: This becomes an easy problem when you make a two direction translation dictionary. For each pair of words, add a Turkish to English entry and an English to Turkish entry. Then you can randomly select a key from the dictionary and ask for the translation.
import random

translator = {}
turkish = []
english = []

def enter_translation():
    print('Welcome to your english program.. To exit please write "exit"\n')
    while True:
        a = input('Your English word: ')
        if a in ('exit', 'stop'):
            break
        b = input('Your Turkısh word: ')
        english.append(a)  # Don't need these lists
        turkish.append(b)
        translator[a] = b
        translator[b] = a

def turkish_translation():
    # To test English -> Turkish
    correct = 0
    random.shuffle(english)
    for word in english:
        answer = input(word + ': ')
        if answer == translator[word]:
            correct += 1
            print("Correct!")
    return correct

def turkish_translation():
    # To test Turkish -> English
    correct = 0
    random.shuffle(turkish)
    for word in turkish:
        answer = input(word + ': ')
        if answer == translator[word]:
            correct += 1
            print("Correct!")
    return correct

def mixed_test():
    # Randomly mix English and Turkish words
    correct = 0
    words = list(translator.keys())
    random.shuffle(words)
    for word in words:
        answer = input(word + ': ')
        if answer == translator[word]:
            correct += 1
            print("Correct!")
    return correct

enter_translation()
print ("You got ", mixed_test(), "correct")

Thank you so much. I was looking for dictionary to use. And u did it exactly how I wanted. Thank you so much.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Solved] Please, help me find a simple mistake AlekseyPython 2 1,757 Jun-17-2021, 12:20 PM
Last Post: AlekseyPython
  [split] Could you please clarify where i did mistake also how run without admin right Abubakkar 1 1,798 Jun-14-2021, 09:32 AM
Last Post: Larz60+
  Please help to me to find my mistake in code leonardin 2 1,850 Nov-29-2020, 04:17 PM
Last Post: Larz60+
  minor mistake in code for factorial spalisetty06 2 1,894 Aug-22-2020, 05:00 PM
Last Post: spalisetty06
  Install Mistake jlerette5 1 1,907 Feb-18-2020, 12:19 AM
Last Post: jefsummers
  What was my mistake in this Python code (easy)? voltman 4 3,462 Nov-19-2019, 09:58 PM
Last Post: snippsat
  countdown script not working..plz help what is mistake randyjack 1 2,123 Oct-28-2019, 06:57 AM
Last Post: perfringo
  Beginner mistake. bbweeg 1 2,045 Aug-17-2019, 07:27 AM
Last Post: perfringo
  Help to understand my mistake TeeMan 8 3,893 Jul-05-2019, 01:42 PM
Last Post: TeeMan
  Need to find a mistake in my code boris602 3 3,154 Jan-11-2018, 01:49 PM
Last Post: boris602

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020