2

Link to the code

import random
import difflib
number = int(input("How many words do you want to practise?"))
words = [*3000 word array*]

for x in range(0, number):
    text_1 = random.randint(0, 3000)
    z = words[text_1]
    print(z)
    text_2 = str(input("Type:"))
    seq = difflib.SequenceMatcher(isjunk=None, a=text_1, b=text_2)
    difference = seq.quick_ratio()
    difference = round(difference, 1)
    print(str(difference) + "% Match")

 print("Thank you!")

The Error message I kept getting: (Line 12)

for elt in self.a: TypeError: 'int' object is not iterable

I have been on a good flow with this program but reached this wall and have tried so many different ways of figuring it out but really couldn't. The program is meant to be a typing test/practice thing. I hope anyone here can help me figure out a solution for my error message, or any suggestions, in general, would be great.

Note: I am very new to this website, so I apologize if any 'format' I use is wrong.

8
  • Code must be posted as text in your question, not as external links or images, or in comments. Regardless, from what it looks like, you're trying to use SequenceMatcher to compare a user-inputted string to a randomly generated integer. Do you mean to be comparing the string representation of the random integer? Commented Nov 18, 2020 at 21:47
  • Welcome to SO! Could you give an example of the text you're inputting? Commented Nov 18, 2020 at 21:50
  • just added it, sorry im new to this site Commented Nov 18, 2020 at 21:52
  • @RandomDavis there isn't any integers in the code, the idea is a random text is generated and you type in that text, and then the two strings are compared. (Typing test/typing practice) Commented Nov 18, 2020 at 21:57
  • @Atassi you say that, yet text_1 is an integer. Did you mean to pass z instead of text_1, like a=z? Commented Nov 18, 2020 at 22:00

1 Answer 1

1

I looked at the difflib.SequenceMatcher documentation, and it seems like a and b need to be sequences. You are giving it an int (text_1). If think you meant

seq = difflib.SequenceMatcher(isjunk=None, a=z, b=text_2)

Note: you should use random.choice to choose a random item from a list, like this z = random.choice(words) that way you dont need text_1

Sign up to request clarification or add additional context in comments.

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.