diff options
| author | Rishi-k-s <rishikrishna.sr@gmail.com> | 2022-06-19 12:23:16 +0530 |
|---|---|---|
| committer | Rishi-k-s <rishikrishna.sr@gmail.com> | 2022-06-19 12:23:16 +0530 |
| commit | 794e8ef672334a143adbd4d4ba674ae2691f6e76 (patch) | |
| tree | 2997203cc2aa2e41274e9477e949e2ee4f298604 | |
| parent | f97b1288e87e884c21b8b9cba5ef412d761160cd (diff) | |
updated for school
| -rw-r--r-- | File Operations (CH2)/school_Dat.txt | 12 | ||||
| -rw-r--r-- | File Operations (CH2)/searchWithCSV.py | 21 | ||||
| -rw-r--r-- | File Operations (CH2)/searchWithUserPassOnlySCV.py | 78 | ||||
| -rw-r--r-- | File Operations (CH2)/userPasswd.csv | 3 |
4 files changed, 100 insertions, 14 deletions
diff --git a/File Operations (CH2)/school_Dat.txt b/File Operations (CH2)/school_Dat.txt index a0ff772..2fec16d 100644 --- a/File Operations (CH2)/school_Dat.txt +++ b/File Operations (CH2)/school_Dat.txt @@ -1,2 +1,10 @@ -abcdef -abcdef
\ No newline at end of file +SUii +df +sf +dfsSui1 +df +ty +gdfdfg +dfg +dfg +dfg
\ No newline at end of file diff --git a/File Operations (CH2)/searchWithCSV.py b/File Operations (CH2)/searchWithCSV.py index 481d7ee..ea91091 100644 --- a/File Operations (CH2)/searchWithCSV.py +++ b/File Operations (CH2)/searchWithCSV.py @@ -66,20 +66,17 @@ elif (get_createOrSearchUser == 2): get_userName = input("Enter the username you want to find: ") get_psswrd = input("Enter the password you want to find: ") searchUserCSV(get_userName,get_psswrd) - try: - wantToReadMoreUserCheck = input("Want to read more users(y/n)?: ") - if(wantToReadMoreUserCheck == 'y'): - readUserBool = True - elif(wantToReadMoreUserCheck =='n'): - readUserBool = False - else: - readUserBool = False - except: - print("Try again :)") + wantToReadMoreUserCheck = input("Want to read more users(y/n)?: ") + if(wantToReadMoreUserCheck == 'y'): + readUserBool = True + elif(wantToReadMoreUserCheck =='n'): + readUserBool = False + else: + readUserBool = False print("-Goodbye-") -elif(get_createOrSearchUser == 2): +elif(get_createOrSearchUser == 3): print("-Goodbye-") else: print("Run the Code again") -file_handlr.close()
\ No newline at end of file +file_handlr.close() diff --git a/File Operations (CH2)/searchWithUserPassOnlySCV.py b/File Operations (CH2)/searchWithUserPassOnlySCV.py new file mode 100644 index 0000000..f83cf5a --- /dev/null +++ b/File Operations (CH2)/searchWithUserPassOnlySCV.py @@ -0,0 +1,78 @@ +import csv + +# file methords +try: + file_handlr = open(r"File Operations (CH2)\userPasswd.csv","r+",newline='\n') +except: + file_handlr = open(r"File Operations (CH2)\userPasswd.csv","w",newline='\n') + +writer_file = csv.writer(file_handlr,) +reader_file = csv.reader(file_handlr) + +#boolians +createUsersBool = True +readUserBool = True + +#function to create user and add it to CSV file functions +def createUserCSV (getNoOfUserToAdd): + userCounter=1 + for each_user in range(getNoOfUserToAdd): + username_gettr = input("Name of user {}: ".format(userCounter)) + password_check = True + while password_check: + password_gettr = input("what is your Password: ") + passwrd_confrm_gettr = input("re-enter your Password: ") + if(password_gettr == passwrd_confrm_gettr): + password_check =False + else: + print("**The passwords doesn't Match**") + user_Details_List = [username_gettr,password_gettr] + writer_file.writerow(user_Details_List) + userCounter +=1 + +#function to read user details from CSV file +def searchUserCSV(userName): + userNOtExists = False + userExists = False + for each_list in reader_file: + if (each_list[0] == userName): + print("********\nUsername: {}\nPassword: {}\n********".format(each_list[0],each_list[1])) + userExists = True + elif (each_list[0] != userName): + userNOtExists = True + if(userNOtExists == True and userExists == False): + print("The user: {} does not exists".format(userName)) + +#Starting menu +get_createOrSearchUser = int(input("1 => Create user\n2 => Search User\n3 => Quit\n=>")) + +#menu functions +if (get_createOrSearchUser == 1): #Creating user + while createUsersBool == True: + getNoOfUsers = int(input("How many users u want to add: ")) + createUserCSV(getNoOfUsers) + try: + wantToAddMoreUserCheck = input("Want to add more users(y/n)?: ") + if(wantToAddMoreUserCheck == 'y'): + createUsersBool = True + elif(wantToAddMoreUserCheck == 'n'): + createUsersBool = False + except: + print("Try again :)") + print("-Goodbye-") +elif (get_createOrSearchUser == 2): #Searching user + while readUserBool == True: + get_userName = input("Enter the username you want to find: ") + searchUserCSV(get_userName) + wantToReadMoreUserCheck = input("Want to read more users(y/n)?: ") + if(wantToReadMoreUserCheck == 'y'): + readUserBool = True + else: + readUserBool = False + print("-Goodbye-") +elif(get_createOrSearchUser == 3): + print("-Goodbye-") +else: + print("Run the Code again") + +file_handlr.close()
\ No newline at end of file diff --git a/File Operations (CH2)/userPasswd.csv b/File Operations (CH2)/userPasswd.csv new file mode 100644 index 0000000..4154c15 --- /dev/null +++ b/File Operations (CH2)/userPasswd.csv @@ -0,0 +1,3 @@ +Human,1 +Bird,2 +Suii,3 |
