Modified python list

Question:

I have a function with two inputs the numeric and the threshold. I want to compute the boolean statement true if the numeric is greater than the threshold. Upon computing my code I get the following error message:

'<' not supported between instances of 'int' and 'list'

See code:

num_list =([10, 1, 3, 7])
result =[]

def hits(num_list,threshold=5):
    
    for x in num_list:
        if threshold<num_list:
            return true 
        
Asked By: Kash

||

Answers:

You are iterating through the for loop with x, but don’t actually call x in the loop. Replace the conditional line with if threshold<x to access the variable x (int) instead of num_list (list). That’s why you’re getting the error about trying to compare an int and a list.

Answered By: bavistr
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.