Python Forum
Check if all the numbers are higher than five and if not...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check if all the numbers are higher than five and if not...
#1
Hello everyone, I hope you are having a great day.
Here's a simple question.

I have a list of numbers:
numbersList = [6, 3, 9, 36, 96, 1, 18, 99, 8, 5, 12, 2]
I want an output like this:
If they are all >= 5, say "You are good to go!"
If it contains numbers < 5, say "You have some invalid numbers" AND they are: [3, 1, 2] (or in any other format)

So far I can handle both situations separately:
for i in numbersList:
    if i < 5:
        print("You have some invalid numbers.")
        break
else:
    print("You are good to go.")
and
invalidNumbers = []
for i in numbersList:
    if i < 5:
        invalidNumbers.append(i)
print(invalidNumbers)
But I'm having trouble mixing the two together. Wall
Reply


Messages In This Thread
Check if all the numbers are higher than five and if not... - by banidjamali - Jan-11-2021, 10:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Higher or lower game SEWII 17 4,082 May-28-2023, 11:59 AM
Last Post: jefsummers
  Random Generator: From Word to Numbers, from Numbers to n possibles Words Yamiyozx 2 1,466 Jan-02-2023, 05:08 PM
Last Post: deanhystad
  Convert list of numbers to string of numbers kam_uk 5 3,058 Nov-21-2020, 03:10 PM
Last Post: deanhystad
  Regular Expressions in Files (find all phone numbers and credit card numbers) Amirsalar 2 4,138 Dec-05-2017, 09:48 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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