|
| 1 | +# pre code |
| 2 | +# main list of contacts |
| 3 | +contacts = {} |
| 4 | + |
| 5 | +# funcs of pre code |
| 6 | +# func to add new contact |
| 7 | +def newContact(): |
| 8 | + while True: |
| 9 | + newContact = raw_input("Name for new Contact : ") |
| 10 | + numForNewContact = raw_input("Number for Contact : ") |
| 11 | + add = raw_input("Add or Try again :") |
| 12 | + if add.strip() == "Add": |
| 13 | + contacts[newContact] = numForNewContact |
| 14 | + print("Contact Successfully added.") |
| 15 | + break |
| 16 | + elif add.strip() == "Try again": |
| 17 | + continue |
| 18 | + else : |
| 19 | + print("Invalid Input.try again") |
| 20 | + continue |
| 21 | + startAgain = raw_input("Add more or continue : ") |
| 22 | + if startAgain.strip() == "Add more": |
| 23 | + print(" ") |
| 24 | + continue |
| 25 | + elif startAgain.strip() == "continue": |
| 26 | + print(" ") |
| 27 | + break |
| 28 | + |
| 29 | +# func to search for a contact |
| 30 | +def searchContact(): |
| 31 | + while True: |
| 32 | + search = raw_input("Search for contact : ") |
| 33 | + toShow = str(search) + contacts[search] |
| 34 | + print(toShow) |
| 35 | + startAgain = raw_input("Search more or continue : ") |
| 36 | + if startAgain.strip() == "Search more": |
| 37 | + print(" ") |
| 38 | + continue |
| 39 | + elif startAgain.strip() == "continue": |
| 40 | + print(" ") |
| 41 | + break |
| 42 | + |
| 43 | +# func to edit a contact |
| 44 | +def editContact(): |
| 45 | + while True: |
| 46 | + whichToEdit = raw_input("Name of Contact of which Number to Edit : ") |
| 47 | + contacts[whichToEdit] = raw_input("Number to add : ") |
| 48 | + startAgain = raw_input("Edit more or continue : ") |
| 49 | + if startAgain.strip() == "Edit more": |
| 50 | + print(" ") |
| 51 | + continue |
| 52 | + elif startAgain.strip() == "continue": |
| 53 | + print(" ") |
| 54 | + break |
| 55 | + |
| 56 | +# main code to interact |
| 57 | +while True: |
| 58 | + print("hello,".title()) |
| 59 | + # part of main code to start or end |
| 60 | + startOrEnd = raw_input("Start or End : ") |
| 61 | + if startOrEnd.strip() == "Start": |
| 62 | + # part of main code to control functions |
| 63 | + addSearchEdit = raw_input("Add or Search or Edit : ") |
| 64 | + if addSearchEdit.strip() == "Add": |
| 65 | + print(newContact()) |
| 66 | + elif addSearchEdit.strip() == "Search": |
| 67 | + print(searchContact()) |
| 68 | + elif addSearchEdit.strip() == "Edit": |
| 69 | + print(editContact()) |
| 70 | + else : |
| 71 | + print("Invalid Input . Try Again") |
| 72 | + continue |
| 73 | + elif startOrEnd.strip() == "End": |
| 74 | + print("Ending...") |
| 75 | + break |
| 76 | + else : |
| 77 | + print("Invalid Input . Try Again") |
| 78 | + continue |
| 79 | + # part of main code to start again or end |
| 80 | + startAgain = raw_input("Start again or End : ") |
| 81 | + if startAgain.strip() == "Start again": |
| 82 | + print("Starting again...") |
| 83 | + continue |
| 84 | + elif startAgain.strip() == "End": |
| 85 | + print("Ending program...") |
| 86 | + break |
| 87 | + else : |
| 88 | + break |
0 commit comments