I want to make a switch case.If option 1 is pressed then some info is added to a csv file and after exit the case if again run the code and choose option 2 then it search some text in file and if found then add something to it.
I have tried the code given below.It runs option 1 correct but give errors in option 2.
from datetime import datetime
import fileinput
today = datetime.now()
In = str(today.strftime("%d/%m/%Y , %H:%M:%S"))
In1=In.rpartition(' , ')[0]
today = datetime.now()
Out = str(today.strftime("%d/%m/%Y , %H:%M:%S"))
out1=Out.rpartition(' , ')[2]
name=input("enter name of employee: ")
attend1=name+" , "+In1
f = open("Attend.csv", "a")
filename="Attend.csv"
while True:
print("1. Enter In Time\n2. Enter Out Time")
choice=input("Enter your choice: ")
if choice == "1":
attend = name+" , "+In
print(attend)
f.write(attend+"\n")
elif choice == "2":
attend = name+" , "+Out
print(attend)
f = open("Attend.csv", "r+")
for lines in f:
if attend1 in lines:
lines=lines.replace(lines,lines+" , "+out1)
f.write(lines+"\n")
else:
print("Please choose the correct entry.")
break
f.close()