Python Forum
How to detect and tell user that no matches were found in a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to detect and tell user that no matches were found in a list
#1
It's one thing to tell someone we have reached the end of a list, but how do we tell the user if no matches were found?

#!/usr/bin/env python3
#PracticePythonExercise03.py

myList = [0,2,5,4,6,7,9,8]

userNumber = int(input("Pick a number: "))

print("the numbers in myList that are smaller than the number you entered are:")

for i in myList:
    if i < userNumber:
        print("Found a number less than " + userNumber + " which is: " + i)
    #If there are no numbers in myLsit smaller than userNumber, then tell the user
    if i == len(myList) and no i < userNumber has not been found...
Reply


Messages In This Thread
How to detect and tell user that no matches were found in a list - by RedSkeleton007 - Jul-17-2018, 03:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  user input values into list of lists tauros73 3 1,088 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  detect equal sequences in list flash77 17 2,926 Oct-28-2022, 06:38 AM
Last Post: flash77
  functional LEDs in an array or list? // RPi user Doczu 5 1,654 Aug-23-2022, 05:37 PM
Last Post: Yoriz
  Split string using variable found in a list japo85 2 1,324 Jul-11-2022, 08:52 AM
Last Post: japo85
  Looking for a way to loop until user enters from a list? PythonW19 7 3,422 Mar-21-2021, 08:56 PM
Last Post: PythonW19
  User input/picking from a list AnunnakiKungFu 2 2,353 Feb-27-2021, 12:10 AM
Last Post: BashBedlam
Question Reset list if user regrets Gilush 1 2,091 Dec-05-2020, 10:55 AM
Last Post: Gilush
  How can I found how many numbers are there in a Collatz Sequence that I found? cananb 2 2,568 Nov-23-2020, 05:15 PM
Last Post: cananb
  delete a Python object that matches an atribute portafreak 2 2,202 Feb-19-2020, 12:48 PM
Last Post: portafreak
  Help with calling list from user input farispython 5 2,858 Nov-03-2019, 03:13 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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