I'm writing code in python 3 and i'm stuck. I need to ask user to give username and password at least 3 times before showing the password . I tried "for" and "try" function but unsuccessful. Please help me to know how to do it.
Thanks in Advance
import os
# Setting dir and Changing it to access files from specific folder
path = 'C:\\Users\\user\\Downloads\\Class Work\\Project Python\\files'
os.chdir(path)
# checking if dir has any files
if len(os.listdir(path)) == 0 :
with open ('name.txt','w') as Name:
Name.write(str(input("Name: ")))
with open('mobile.txt','w') as Mob:
Mob.write(str(input("Mobile No.: ")))
with open('email.txt','w') as email:
email.write(str(input("Email ID: ")))
with open('password.txt','w') as password:
password.write(input("password: "))
else:
# Authrntication
a= str(input("Enter Email ID: "))
b=input("Enter Password: ")
with open('email.txt','r') as email:
x = email.read()
with open('password.txt','r') as password:
y= password.read()
if x==a and y==b:
# If successful change password
with open('password.txt','w') as password:
password.write(input("New Password "))
#try 3 times before showing password
else:
# IF not successful Show Password
# after verification of EMail ID and phone
c = str(input("Enter Email ID: "))
d = input("Enter Phone: ")
with open('email.txt','r') as email:
s = email.read()
with open("mobile.txt",'r') as mobile:
t = mobile.read()
if c==s and d==t:
with open('password.txt','r') as password:
p = password.read()
print(p)