0

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 
        
4
  • 3
    What do you think the line num_list>7==True does? Commented Oct 11, 2022 at 18:38
  • What is the purpose of the constant 4? What do you mean by "if a certain threshold is reached"? Do you mean if the threshold value occurs in the list? Commented Oct 11, 2022 at 18:43
  • The error message is quite clear, you are comparing an int, in this case, threshold with a list, num_list using the < operator, but that operation is not supported. Did you intend to use x instead of num_list? Commented Oct 11, 2022 at 18:56
  • you want True(uppercase) instead of true (lowercase - invalid name) Are you sure you want to return True after only one value is above the threshold? Commented Oct 11, 2022 at 18:58

1 Answer 1

1

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.

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.