def SaveData(allRec):
with open ("trainingSchedule.txt","w") as fh:
for x in AllRec :
rec = ",".join(x)
fh.write(rec+"\n")
def AddSchedule(AllRec):
trainingId = input("Enter training ID : ")
trainingDate = input("Enter training date : ")
trainingTime = input("Enter training time : ")
trainingVenue = input("Enter training venue : ")
trainingCoach = input("Enter training coach : ")
trainingStudent = input("Enter training students : ")
rec = [trainingId,trainingDate,trainingTime,trainingVenue,trainingCoach,trainingStudent]
AllRec.append(rec)
SaveData(AllRec)
return AllRec
def MainMenu():
choice = 0
print("1. Add training schedule ")
print("2. Modify training schedule ")
print("3. Delete training schedule ")
print("4. Search training schedule ")
print("5. Exit ")
choice = input("Please enter your choice : ")
return int(choice)
def ModifySchedule(AllRec):
sValue = input("Please enter training id to modify : ")
ind = -1
for x in range(len(AllRec)):
if (sValue in AllRec[x][0]):
ind = x
break
if ind != -1 :
print(AllRec[ind][0]+"\t"+AllRec[ind][1]+"\t"+AllRec[ind][2]+"\t"+AllRec[ind][3]+"\t"+AllRec[ind][4]+"\t"+AllRec[ind][5])
AllRec[ind][0] = input("Please enter a new training ID : ")
AllRec[ind][1] = input("Please enter a new training date : ")
AllRec[ind][2] = input("Please enter a new training time : ")
AllRec[ind][3] = input("Please enter a new training venue : ")
AllRec[ind][4] = input("Please enter a new training coach : ")
AllRec[ind][5] = input("Please enter a new training students : ")
SaveData(AllRec)
print("Data saved \n")
else :
print("Search value not found.....\n")
def ReadInitialData(allRec):
with open("trainingschedule.txt","r") as fh:
for rec in fh:
listRec = rec.strip().split(",")
allRec.append(listRec)
return allRec
def DeleteSchedule(AllRec):
sValue = input("Please enter training id to delete : ")
AllRec.remove("1")
#Main Logic
AllRec = ReadInitialData([])
while True :
ch = MainMenu()
if ch == 1 :
AllRec = AddSchedule(AllRec)
elif ch == 2 :
AllRec = ModifySchedule(AllRec)
elif ch == 3 :
AllRec = DeleteSchedule(AllRec)
elif ch == 4 :
SearchSchedule(AllRec)
elif ch == 5 :
print("Have a nice day")
break;
ans = input("Do you want to continue (y/n) : ")
if ans == "n":
print("Have a nice day")
break
We have no idea what problem this code is trying to solve. Please provide the detailed problem instructions for this along with any data files needed to solve the problem.
this is a question which required us to create a basketball training schedule with features such as add,modify,delete,search from to the list
The code in the DeleteSchedule
function is incorrect. To delete an item from the AllRec
list, you need to find the index of the item first and then remove it using the del
statement or the remove
method of the list.
how should i code it
i am deleting the whole entry according to the training id but i am stuck
def SaveData(allRec):
# Open the text file for writing and save the records
with open ("trainingSchedule.txt","w") as fh:
for x in allRec:
# Join the elements of each record and separate them with commas
rec = ",".join(x)
# Write the record to the text file and add a newline character
fh.write(rec+"\n")
def AddSchedule(allRec):
# Ask the user for the training details
trainingId = input("Enter training ID : ")
trainingDate = input("Enter training date : ")
trainingTime = input("Enter training time : ")
trainingVenue = input("Enter training venue : ")
trainingCoach = input("Enter training coach : ")
trainingStudent = input("Enter training students : ")
# Store the training details in a list
rec = [trainingId,trainingDate,trainingTime,trainingVenue,trainingCoach,trainingStudent]
# Add the record to the allRec list
allRec.append(rec)
# Save the updated list to the text file
SaveData(allRec)
# Return the updated list
return allRec
def MainMenu():
# Print the main menu options
choice = 0
print("1. Add training schedule "
What does your new code look like for the DeleteSchedule function? You need to use the algorithm that @Nathan.clark88 has supplied you and try to write the code that implements that algorithm.
You already know how to get the index by the training id, because you have already written code that does just that.
We are not here to write code for you. We are here to guide you to a code solution. You must put the effort in to write the code.