Home > Back-end >  why it is not correct (numpy.testing.assert_equal in python3)
why it is not correct (numpy.testing.assert_equal in python3)

Time:12-27

i don't know why not correct, anyone can help please. `

def issc(x):
    avg = []
    for i in range(len(x)) :
        score = x[i]
        score = score.split(",")
        avg.append((int(score[0])   int(score[1])   int(score[2])) //3)
    win = max(avg)
    pos = avg.index(win)   1
    return "("   str(pos)   ", "   str(win)   ")"

import numpy as np
sc=0
try:
    np.testing.assert_equal(issc(['50,45,60', '80,75,85', '50,65,60', '85,80,79', '60,75,62']), (4, 81))
    print('correct')
    print(sc)
except Exception as e:
    print('not correct')
    print(e)

`

output: not correct

Items are not equal:
ACTUAL: '(4, 81)'
DESIRED: (4, 81)

i don't know why not correct, anyone can help please.

CodePudding user response:

def issc(x):
    avg = []
    for i in range(len(x)) :
        score = x[i]
        score = score.split(",")
        avg.append((int(score[0])   int(score[1])   int(score[2])) //3)
    win = max(avg)
    pos = avg.index(win)   1
    return pos, win

CodePudding user response:

def issc(x):
avg = []
for i in range(len(x)) :
    score = x[i]
    score = score.split(",")
    avg.append((int(score[0])   int(score[1])   int(score[2])) //3)
win = max(avg)
pos = avg.index(win)   1
return "("   str(pos)   ", "   str(win)   ")"

import numpy as np sc=0 try: np.testing.assert_equal(issc(['50,45,60', '80,75,85', '50,65,60', '85,80,79', '60,75,62']), (4, 81)) print('correct') print(sc) except Exception as e: print('not correct') print(e)

CodePudding user response:

numpy.testing.assert_equal is a function in the numpy.testing module that allows you to test if two objects are equal. It is typically used to test the output of a function or to compare two arrays.

Here's an example of how to use numpy.testing.assert_equal to test if two arrays are equal:

import numpy as np

# Create two arrays to compare
a = np.array([1, 2, 3])
b = np.array([1, 2, 3])

# Use numpy.testing.assert_equal to test if the arrays are equal
np.testing.assert_equal(a, b)

# If the arrays are equal, the code will continue to execute. If the arrays 
are not equal,
# an AssertionError will be raised.

You can also use numpy.testing.assert_equal to compare other types of objects, such as numbers or strings. For example:

import numpy as np

# Compare two numbers
a = 1
b = 1
np.testing.assert_equal(a, b)

# Compare two strings
a = "hello"
b = "hello"
np.testing.assert_equal(a, b)

If you want to customize the error message that is displayed when the objects are not equal, you can pass a message as an optional argument to numpy.testing.assert_equal. For example:

import numpy as np

# Create two arrays to compare
a = np.array([1, 2, 3])
b = np.array([1, 2, 4])

# Use numpy.testing.assert_equal to test if the arrays are equal, with a 
custom error message
np.testing.assert_equal(a, b, "Arrays are not equal")

# If the arrays are not equal, the AssertionError will include the custom 
 error message
  • Related