Discuss Scratch

mbrick2
Scratcher
1000+ posts

EOF Error

Here is my code:
# setup
keyProb = []
result = []
key = ['apple','banana','hello', 'world']
equalLetters = 0
# run code
print('Please input one of the following \n apple \n banana\n world\n')
inp = input()
r1 = 0
r2 = 0
for x in range (len(key)):
    print('Loading')
    for i in len(inp):
        keyProb.append(' ')
        if key[r1[r2]] == inp[r2]:
            keyProb[len(keyProb)] = '#'
            equalLetters = equalLetters + 1
        r2 = r2 + 1
    r2 = 1
    result.append(equalLetters)
    r1 = r1 + 1
    keyProb.clear()
print('')
it outputs
Traceback (most recent call last):
  File "./prog.py", line 8, in <module>
EOFError: EOF when reading a line
What am I doing wrong??
MagicCrayon9342
Scratcher
1000+ posts

EOF Error

EOF commonly referred to as “End of File” usually has something to do with the ending of a loop or function.
MagicCrayon9342
Scratcher
1000+ posts

EOF Error

These are the issues with your code:
some being cleanliness and PEP standards but the last one makes sense.

Last edited by MagicCrayon9342 (Dec. 15, 2021 21:45:11)

mbrick2
Scratcher
1000+ posts

EOF Error

MagicCrayon9342 wrote:

These are the issues with your code:
some being cleanliness and PEP standards but the last one makes sense.
Thanks.
Also what website did you use for that??
mbrick2
Scratcher
1000+ posts

EOF Error

# setup
keyProb = []
result = []
key = ['apple', 'banana', 'hello', 'world']
equalLetters = 0
# run code
print('Please input one of the following \n apple \n banana\n hello\n world\n')
inp = 'appel'
#input()
r1 = 0
r2 = 0
for x in range (len(key)):
    print('Loading')
    for x in (len(inp)):
        keyProb.append(' ')
        if key[r1[r2]] == inp[r2]:
            keyProb[len(keyProb)] = '#'
            equalLetters = equalLetters + 1
        r2 = r2 + 1
    r2 = 1
    result.append(equalLetters)
    r1 = r1 + 1
    keyProb.clear()
print('\n')
output:
Traceback (most recent call last):
  File "./prog.py", line 14, in <module>
TypeError: 'int' object is not iterable
MagicCrayon9342
Scratcher
1000+ posts

EOF Error

Our encounter with for-loops introduced the term iterable - an object that can be “iterated over”, such as in a for-loop. Definition: An iterable is any Python object capable of returning its members one at a time, permitting it to be iterated over in a for-loop.
god286
Scratcher
1000+ posts

EOF Error

# setup
keyProb = []
result = []
key = ['apple', 'banana', 'hello', 'world']
equalLetters = 0
# run code
print('Please input one of the following \n apple \n banana\n hello\n world\n')
inp = 'appel'
#input()
r1 = 0
r2 = 0
for x in range(len(key)):
    print('Loading')
    for x in range(len(inp)):
        keyProb.append(' ')
        if key[r1[r2]] == inp[r2]:
            keyProb[len(keyProb)] = '#'
            equalLetters = equalLetters + 1
        r2 = r2 + 1
    r2 = 1
    result.append(equalLetters)
    r1 = r1 + 1
    keyProb.clear()
print('\n')
might work?

Last edited by god286 (Dec. 15, 2021 23:31:49)

mbrick2
Scratcher
1000+ posts

EOF Error

god286 wrote:

# setup
keyProb =
result =
key =
equalLetters = 0
# run code
print('Please input one of the following \n apple \n banana\n hello\n world\n')
inp = ‘appel’
#input()
r1 = 0
r2 = 0
for x in range(len(key)):
print('Loading')
for x in range(len(inp)):
keyProb.append(' ')
if key[r1] == inp:
keyProb = ‘#’
equalLetters = equalLetters + 1
r2 = r2 + 1
r2 = 1
result.append(equalLetters)
r1 = r1 + 1
keyProb.clear()
print('\n')
Traceback (most recent call last):
  File "./prog.py", line 16, in <module>
TypeError: 'int' object is not subscriptable
Chiroyce
Scratcher
1000+ posts

EOF Error

mbrick2 wrote:

Traceback (most recent call last):
File “./prog.py”, line 8, in <module>
EOFError: EOF when reading a line
Wait i'm getting this?!

Traceback (most recent call last):
File "/Users/Chiroyce/Downloads/test.py", line 13, in <module>
for i in len(inp):
TypeError: 'int' object is not iterable

Looks like the line
    for i in len(inp):
should be
    for i in range(len(inp)):
mbrick2
Scratcher
1000+ posts

EOF Error

thanks

Chiroyce wrote:

mbrick2 wrote:

Traceback (most recent call last):
File “./prog.py”, line 8, in <module>
EOFError: EOF when reading a line
Wait i'm getting this?!

Traceback (most recent call last):
File "/Users/Chiroyce/Downloads/test.py", line 13, in <module>
for i in len(inp):
TypeError: 'int' object is not iterable

Looks like the line
    for i in len(inp):
should be
    for i in range(len(inp)):
Greg8128
Scratcher
500+ posts

EOF Error

mbrick2 wrote:

Here is my code:
# setup
keyProb = []
result = []
key = ['apple','banana','hello', 'world']
equalLetters = 0
# run code
print('Please input one of the following \n apple \n banana\n world\n')
inp = input()
r1 = 0
r2 = 0
for x in range (len(key)):
    print('Loading')
    for i in len(inp):
        keyProb.append(' ')
        if key[r1[r2]] == inp[r2]:
            keyProb[len(keyProb)] = '#'
            equalLetters = equalLetters + 1
        r2 = r2 + 1
    r2 = 1
    result.append(equalLetters)
    r1 = r1 + 1
    keyProb.clear()
print('')
it outputs
Traceback (most recent call last):
  File "./prog.py", line 8, in <module>
EOFError: EOF when reading a line
What am I doing wrong??
What is this code supposed to do? For all we know, it IS supposed to produce an EOF error
mbrick2
Scratcher
1000+ posts

EOF Error

Greg8128 wrote:

mbrick2 wrote:

Here is my code:
# setup
keyProb = []
result = []
key = ['apple','banana','hello', 'world']
equalLetters = 0
# run code
print('Please input one of the following \n apple \n banana\n world\n')
inp = input()
r1 = 0
r2 = 0
for x in range (len(key)):
    print('Loading')
    for i in len(inp):
        keyProb.append(' ')
        if key[r1[r2]] == inp[r2]:
            keyProb[len(keyProb)] = '#'
            equalLetters = equalLetters + 1
        r2 = r2 + 1
    r2 = 1
    result.append(equalLetters)
    r1 = r1 + 1
    keyProb.clear()
print('')
it outputs
Traceback (most recent call last):
  File "./prog.py", line 8, in <module>
EOFError: EOF when reading a line
What am I doing wrong??
What is this code supposed to do? For all we know, it IS supposed to produce an EOF error
It is supposed to compare the input with the keywords in numbers
Greg8128
Scratcher
500+ posts

EOF Error

mbrick2 wrote:

Greg8128 wrote:

mbrick2 wrote:

Here is my code:
# setup
keyProb = []
result = []
key = ['apple','banana','hello', 'world']
equalLetters = 0
# run code
print('Please input one of the following \n apple \n banana\n world\n')
inp = input()
r1 = 0
r2 = 0
for x in range (len(key)):
    print('Loading')
    for i in len(inp):
        keyProb.append(' ')
        if key[r1[r2]] == inp[r2]:
            keyProb[len(keyProb)] = '#'
            equalLetters = equalLetters + 1
        r2 = r2 + 1
    r2 = 1
    result.append(equalLetters)
    r1 = r1 + 1
    keyProb.clear()
print('')
it outputs
Traceback (most recent call last):
  File "./prog.py", line 8, in <module>
EOFError: EOF when reading a line
What am I doing wrong??
What is this code supposed to do? For all we know, it IS supposed to produce an EOF error
It is supposed to compare the input with the keywords in numbers
In what way?
Try describing the function in such a way that someone else would be able to create it, and have it work exactly the way you want, using only the description
mbrick2
Scratcher
1000+ posts

EOF Error

Greg8128 wrote:

mbrick2 wrote:

Greg8128 wrote:

mbrick2 wrote:

Here is my code:
# setup
keyProb = []
result = []
key = ['apple','banana','hello', 'world']
equalLetters = 0
# run code
print('Please input one of the following \n apple \n banana\n world\n')
inp = input()
r1 = 0
r2 = 0
for x in range (len(key)):
    print('Loading')
    for i in len(inp):
        keyProb.append(' ')
        if key[r1[r2]] == inp[r2]:
            keyProb[len(keyProb)] = '#'
            equalLetters = equalLetters + 1
        r2 = r2 + 1
    r2 = 1
    result.append(equalLetters)
    r1 = r1 + 1
    keyProb.clear()
print('')
it outputs
Traceback (most recent call last):
  File "./prog.py", line 8, in <module>
EOFError: EOF when reading a line
What am I doing wrong??
What is this code supposed to do? For all we know, it IS supposed to produce an EOF error
It is supposed to compare the input with the keywords in numbers
In what way?
Try describing the function in such a way that someone else would be able to create it, and have it work exactly the way you want, using only the description
finds similarities inbetween input and keywords.
https://scratch.mit.edu/projects/617626821/
Greg8128
Scratcher
500+ posts

EOF Error

mbrick2 wrote:

finds similarities inbetween input and keywords.
https://scratch.mit.edu/projects/617626821/
I assume that you want to do the following:
Create a comparison test “cmp” which takes 2 strings and returns in how many positions they both have a letter and the letters match
Given an input string, run “cmp” on the string and each of several other strings

In Haskell, you would write this as:
strTest xs ys = length . filter id $ zipWith (==) xs ys
This just generates a list where there is “True” at every position where the letters are the same and “False” everywhere else. Then, it counts the number of “True”s.

The Python equivalent is:
str_test = lambda xs, ys: sum(map(operator.eq, xs, ys))

Powered by DjangoBB