First set of code.
def main():
#Create a bool variable to use as a flag.
found = False
#Get the search value.
search = raw_input('Enter a number to search for: ')
#Open the numbers.txt file.
account_file = open('numbers.txt', 'r')
#Read the first record.
line = number_file.readline()
#Determine whether this record matches the search value.
if line == search:
#Display the record.
print 'Number:' , line
#Set the found flag to True.
found = True
#Read the next line
line = number_file.readline()
#Close the file.
number_file.close()
#If the search value was not found in the file
#display a message.
if not found:
print 'The number was not found.'
#Call the main function.
main()
Second set of code.
def main():
#Open file for reading
infile = open('numbers.txt', 'r')
#Read the contents of the file into a list
number = infile.readlines()
#Convert each element into an int
index = 0
while index !=len(account_number):
number = [int(num) for num in number]
index +=1
#Get an the search value
search = raw_input('Enter a number to search for: ')
#Determine whether this record matches the search value.
if search in number:
print 'Number found.', search
else:
print 'The number was not found.'
#Close the file.
infile.close()
#Call the main function.
main()
If someone could point me in the right direction, it would be very much appreciated.

New Topic/Question
Reply



MultiQuote




|