Jul-19-2018, 03:21 AM
woooee, I had to alter your code, because the user_num argument in your code was not defined.
Also, I managed to make my program work using an empty list called smallerNums:
Also, I managed to make my program work using an empty list called smallerNums:
#!/usr/bin/env python3 #PracticePythonExercise03.py myList = [0,2,5,4,6,7,9,8] #userNumber = int(input("Pick a number: ")) ##def findSmaller(): ## userNumber = int(input("Pick a number: ")) ## for test in myList: ## if test < userNumber: ## print("Found a number less than " + str(userNumber) + " which is: " + str(test)) ## #return True ## else: ## return False ## #if none are found, then return false. ## #return False def findSmaller2(): userNumber = int(input("Pick a number: ")) smallerNums = [] for test in myList: if test < userNumber: smallerNums.append(test) if not smallerNums:#if smallerNums is empty print("No numbers smaller than " + str(userNumber) + " were found in myList.") else: print("The numbers smaller than " + str(userNumber) + " found in myList were:") for i in smallerNums: print(i) findSmaller2()But is there a way to accomplish the same result without storing every value from myList smaller than userNumber into another list, and that will not return true after only one value is found that fits the criteria?