Python Forum

Full Version: Help needed please
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all, hoping someone can help me. I have an array that finds the range in difference between highest and lowest positive integers. I can accomplish this bit, however if a negative integer(s) is inserted within the array. I need to find a way that the negative integers aren't included in the output?

daily_sales = [-5, 8, 12, 23, 7, 56, 99, 65]

lowest = min(daily_sales)
highest = max(daily_sales)
negative = 0

if x in range(len([daily_sales])) < 1:
    print()
else:
    difference = highest - lowest
    

print(difference)
I'm not sure if I got the idea, but if you want to remove the negative numbers from a list:
daily_sales = [x for x in daily_sales if x >= 0]
You can simply remove the negative sales
sales = [x for x in daily_sales if x >= 1]
Thank you for your help, solution to problem is solved.