I'm fairly new to python, and I've started creating a little script that saves a user's name into a text file. I want to have a list of blacklisted characters that can't appear in one's name, but I only manage to not let the blacklisted characters BE the name. How can I do this?
Name = input("What is your name?\n")
NameDoc = open("Name.txt", "w")
Black_List = ["B", "A"]
if Name in Black_List:
print("Blacklisted Name")
elif len(Name) > 10:
print("Sorry, 10 characters max!")
else:
NameDoc.write(Name)
NameDoc.close()
Name2 = open("Name.txt", "r")
print("Name accepted!")
print("Hello " + Name2.read())
Name2.close()
try:
NameDoc.close()
except:
pass