The idea is that the function "search()" should take the name of a customer and a list of customers as it's parameters and check whether the customer was in the customer.txt (then return True) or not (then return False).
The specifications are: 1) take the name of a customer and a list of customers (the list made by writeData(), customer.txt) as its parameters 2) check if name is in the list 3) If it is, return True ; if not, return False.
Currently,
1) whenever I type S in the menu it tells me it is missing two required positional arguments
Traceback (most recent call last):
cdman() File "test.py", line 55, in cdman menu() File "test.py", line 24, in menu search() TypeError: search() missing 2 required positional arguments: 'name' and 'filename'
2) If I simply call "search() " in the shell, it says " name "search" is not defined ", both before and after calling " cdman() " first
3) If I were to have the name " Jacob Walker " in the file and attempt to search for it, it will highlight Walker and say invalid syntax
def cdman():
def menu():
print('*------------------------*')
print('| Customer Database Menu |')
print('*------------------------*\n')
choice = input('D: Create/Update Customer Data\nR: Display Database\nS: Search for User\nE: End Program\n')
if choice == 'D':
writeData()
menu()
elif choice == 'S':
search()
menu()
elif choice == 'R':
readData()
menu()
elif choice == 'E':
print('PROGRAM TERMINATED')
def writeData():
while True:
database = open('customer.txt', 'a')
name = input('Name: ')
if name == '-1':
database.close()
return False
else:
id_num = input('ID: ')
database.write('Name: ' + name + ' ')
database.write('ID: ' + id_num + '\n')
def readData():
database = open('customer.txt', 'r')
for line in database:
print(line)
def search(name, filename):
if name in open(filename).read():
print('True')
else:
print('False')
menu()
cdman()