Reputation: 297
I am coding a function which takes a search enquiry for a list of tuples (Employee records) and then outputs based on the enquiry parameters. For example, in my problem I am searching a salary range with a minimum of 30000 and a maximum of 100000, I would expect this to output the names of staff members within this salary range, however it instead give the output of no results found, which is incorrect as there are many staff members within this salary range.
As a comparison, a minimum of 0 and a maximum of 100000 would output all of the records which is correct, however when putting the minimum above 30000 it always outputs no result found which is infact correct as there are many staff salaries in the list of tuples which are over 30000.
Below is the part of the code which I believe is causing the problem (Not posting the whole code as this is a coursework project and I dont want to encourage plagiarism on my work):
This should actually output results as there are employees within this salary range, but it is apparent that something is wrong in the code, and I cannot see what this is!
I hope someone can help, this has been bothering me for a while and I really cant seem to find the solution to this!
Upvotes: 0
Views: 26
Reputation: 550
I think your program exits after the first tuple is processed. Is the first tuple outside of the salary range? If so, it skips the if statement and goes to the elif. querFound is still false and x is still 0, so it prints and exits.
My suggestion is to replace your entire while loop with this for loop:
for t in editTup:
sal = int(t[2])
if sal > salMin and sal < salMax:
print(t[4] + " " + t[3])
querFound = True
if not querFound:
print('No results found')
Upvotes: 1