summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRishi-k-s <rishikrishna.sr@gmail.com>2022-06-26 17:18:54 +0530
committerRishi-k-s <rishikrishna.sr@gmail.com>2022-06-26 17:18:54 +0530
commit3c99f6a625e3e6446f93e8ea70b4d5fc7acc5dbc (patch)
treed7ce657b08ec6c2bd82c9626d9ff5ca89e3a71ff
parentc948b8df2c7f1e14e252bf1c8f9d1b634ad62056 (diff)
bugs fixed :)
-rw-r--r--File Operations (CH2)/sirCode.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/File Operations (CH2)/sirCode.py b/File Operations (CH2)/sirCode.py
new file mode 100644
index 0000000..0d1b6e0
--- /dev/null
+++ b/File Operations (CH2)/sirCode.py
@@ -0,0 +1,48 @@
+import csv
+
+fp = open("usr_pswd.csv", "w", newline='\n')
+fp.close()
+
+def adduser(usr_list):
+ add_fp = open("usr_pswd.csv","a",newline='\n')
+ writer_obj = csv.writer(add_fp)
+ writer_obj.writerow(usr_list)
+ print("User Added")
+ add_fp.close()
+
+
+def search():
+ reader_fp = open("usr_pswd.csv", "r", newline='\n')
+ reader_obj = csv.reader(reader_fp)
+ name = input("Enter name to search:")
+ user_found = False
+ user_not_found = False
+ for row in reader_obj:
+ if row[0] == name:
+ user_found = True
+ print("User Name : ", row[0], "\nPassword : ", row[1])
+ elif row[0] != name:
+ user_not_found = True
+ if user_found == False and user_not_found == True:
+ print(name, " not found")
+ reader_fp.close()
+
+
+c = 'y'
+while c == 'y' or c == 'Y':
+ choice = int(input("1. Add User\n2. Search User\n3. Exit\nEnter your choice:"))
+
+ if choice == 1:
+ ch = 'y'
+ while ch == 'y' or ch == 'Y':
+ name = input("Enter User Name: ")
+ password = input("Enter Password: ")
+ adduser([name, password])
+ ch = input("Do you want to add more user(y/n) : ")
+
+ elif choice == 2:
+ search()
+ elif choice == 3:
+ print("Program Completed")
+ exit(0)
+ c = input("Do you want to perform more operation(y/n) : ") \ No newline at end of file