The following code appears to work. Note I have commented out the parts that write the details to the file, and most of the sleep calls (why are they there?).
import time
def password():
ans = "no"
while ans == 'no' or ans == 'n':
a = 0
password = input("Enter a password. \n(Must contain at least 1 number, 1 captial, 5 characters and have no special characters)\n")
if password.isalnum() == True:
if password != password.lower():
if len(password) > 4:
for i in range(len(password)):
try:
float(password[i])
except:
a = a
else:
a = a + 1
if a > 0:
ans = input("Your password is " + password + "\nIs this the password you wanted? Y/N\n")
ans = ans.lower()
if ans == 'y' or ans == 'yes':
print("Your password is being added to the database.\n")
print("...\n")
print("Your password has been set.")
else:
print("Test failed!")
else:
print("You need at least 1 number.")
else:
print("You must have at least 5 characters.")
else:
print("You need at least 1 capital.")
else:
print("That contains a special character.")
def username():
ans = "no"
while ans == "no" or ans == "n":
username = input("What do you want your username to be?\n")
if username.isalnum() == True:
if len(username) > 4:
ans = input("Your username is " + username + " is this correct? Y/N\n")
ans = ans.lower()
if ans == "y" or ans == "yes":
print("Your username is being added to the database.\n")
print("...\n")
print("Your username has been set.")
password()
else:
print("Test failed!")
else:
print("Your username has to have more than 4 characters.")
else:
print("You username cannot have a special character.")
username()