Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help needed please
#1
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)
Reply
#2
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]
Reply
#3
You can simply remove the negative sales
sales = [x for x in daily_sales if x >= 1]
Reply
#4
Thank you for your help, solution to problem is solved.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020