Library:
Q.A login register is maintained in the library of
VITCC in which, the register number of students are recorded when they enter
the library. Sometimes it happens that the students visit the library more than
once in a day and hence duplicate entries occur so frequently in the register.
The librarian wants to have a report of all students who have visited on a
particular day, ‘x’. Given the list of students who visited the library
on the day ‘x’, write an algorithm and the subsequent Python program to prepare
a report with unique register number of students. Also read a register number
‘r’ and search for it in the list. Print ‘Found’ if ‘r’ is in the list and
print ‘Not found’ otherwise.
Input Format:
First line contains the number of students visited,
‘n’
Second line contains the register number of first
entry
Third line contains the register number of second
entry
. . .
N+1th line contains the register number of n-th entry
Next line contains the register number ‘r’ that has to
be searched
Output Format:
A list without duplicate entries
Print either ‘Found’ or ‘Not found’
Boundary Conditions:
Number of students visited >=0
Input:
The
number of students, list of registration numbers, the registration number that
has to be searched.
Processing:
students
= []
for
i in range(n):
students.insert(i,input())
Output:
Display
if the registration number searched was found or not.
Program:
n
= int(input())
if
n <= 0:
print('Invalid Input')
else:
students = []
for i in range(n):
temp = input().rstrip()
if temp not in students:
students.insert(i,temp)
temp = input().rstrip()
if temp not in students:
students.insert(i,temp)
r = input()
print(students)
if r in students:
print('Found')
else:
print('Not found')
Algorithm:
Step1.
Get the number students from the user.
Step2.
If n is less than or equal to zero display invalid input else move on to the
next step.
Step3.
Initialize students as an empty list and i as 0.
Step4.
Repeat till i is less than n
Step4.1.
Insert the registration number entered by the user into the ith position of the
student list if not in students list else decrement by 1.
Step5.
Get the registration number that has to be searched.
Step6.
If the registration number is found in the students list then display found
else display not found.
Step7.End
Flowchart:
To edit this flowchart click on this
No comments:
Post a Comment