could somebody help troubleshoot my python program every time i try to quot view quo 5150638
Could somebody help troubleshoot my python program? Every time I try to “view” a contact it give me this error message: “Traceback (most recent call last):
File “C:/Users/mrjon/Desktop/COP2002/contacts_jones.py”, line 67, in
main()
File “C:/Users/mrjon/Desktop/COP2002/contacts_jones.py”, line 56, in main
view(name)
File “C:/Users/mrjon/Desktop/COP2002/contacts_jones.py”, line 18, in view
if row[0]== name:
IndexError: list index out of range”
I will also include the CVS file bellow that i've included in my program.
import CSv def list (): with open (“contacts.csv”) as Csv file: csv reader- csv.reader (csv file, delimiter-“,”) lis [line.split (“,”) for line in csv file for i,x in enumerate (lis): print (“0. {1}”.format (i+1,x [0]) def view (name) with open (“contacts.csv”) as csv file: csv reader- csv.reader (csv file, delimiter-“,”) for row in csv reader: if row[0]-= name : print (“Name: “+row [0]) print (“Email: “+row [1]) print (“Phone: “+row [2]) return print (“The contact name are not present in list.”) name def add () name input (“Name email-input (“Email: “) phone input (“Phone: “) with open (“contacts.csv”, a”) as csvFile: writer csv.writer (csvFile) writer.writerow name, email, phone]) “was added”) print (name, def delete () name-input (“Name: “) “has been deleted”) print (“Contact” name, def main () print (“Contact Managern”) print (“COMMAND MENU”) print (“1ist print (“view Displaying all contacts”) View a contact”) Add a contact”) print (“add Delete a contact”) print (“delete Exit program”) print (“exit _ choice-input (“Command: “) while True: if choice- ” list “: list () elif choice-“view” name-input (“Enter Name: “) view (name) elif choice- “add” add ( elif choice-= “exit”: print (“Bye!”) break else print (“Invalid commandn”) print () choice-input (“Command: “) main contacts Excel AutoSave Off Formulas File Page Layout Review View Help Search Home Insert Data X Calibri 11 General AM T A Paste Clipboard Font Alignment Number “Guido van Rossum” A1 A C F G H K 1 [“Guido v 2 [“Eric Idle “eric@eri “44 20 7946 0958” 3 [“Lizard D “duck@li: “352 123 4567”] “guido@ “31 0474 33 88 26” 4 [“Morris F “morrie@ “203-678-1234”] 5 jonathan mrjones@345-345-8705 7 rick rick@ufl.e 444 8 9 jondrow jondrow@555-555-5555 10 11 jimmy jimmy@u578-535-1523 12 13 cedric cedric@ui458-111-2374 14 LL