Reputation: 5
This is the part of my code that I'm having trouble with. for the part if nums >= -999 is not working. i have tried int(nums) >= -999 too. I'm not exactly sure how to fix this problem. The error I get as the way the code is below is unorderable types: list() >= int()
from statistics import mean
nums = [int(input("Enter Numbers ")) for _ in range(6)]
if nums >= -999:
print("Sentinel value was entered")
print([x for x in nums if x > mean(nums)])
Upvotes: 0
Views: 81
Reputation: 527378
If you just want to check if any of the numbers in a list is less than or equal to -999
:
if any(x <= -999 for x in nums):
# at least one of the numbers in nums was -999 or below
Upvotes: 4
Reputation: 5929
I'm not quite sure what you're trying to do, but if you are trying to find out if there are any number >=-999 in the list, you could do:
too_large=[i for i in nums if i>=-999]
if (too_large):
print("Sentinel value was entered")
This builds up a list (a subset of nums) where the number is >=-999, and puts it in too_large; then, if this list has any elements (if (too_large):
) it prints the message.
Note that -999 is a very small number, many numbers (e.g. 1) are larger than this. I don't know if this was your intention.
Upvotes: 2