Errors in a password protected program

Hi, I tried to make a easy program where you have to enter a pasword and a code to see your marks. But this is the script and this is the error

print("Hello, I am PythonBoys personal marks privacy assistant.")

Question_1 = input("Would you like to see your marks?: ")


if Question_1 == "Yes":
  Password_1 = input("Please type the personal password that is given by me to continue:")
else:
  print("BROKEN PROGRAM TRY AGAIN")
  
if Password_1 == "Dev":
  Code_1 = int(input("Please type the 5 digit code to continue:"))
elif Code_1 == "24500":
  print("Congratualtions you have successfully breached through high security system")
else:
  print("Wrong password and code") 
 
User_Input = input("Which subject would you like to see your marks of?: ")

if User_Input == "Maths":
  print("Your", User_Input, "marks is XXXXXXXX")


This is the error when I try to type a wrong password

I am still a beginner to python so please dont judge me for creating this program

There are some things you should consider:

  • Password_1 is assigned only if answer to Question_1 is ‘Yes’. If it is something else, there will not be Password_1. In the code what follows you use Password_1 and this will raise NameError

  • if-elif-else will execute only one branch. Code_1 is assigned only when Password_1 is ‘Dev’ and no other branches (elif, else) will be executed/tested after that. From another hand if Password_1 is not ‘Dev’ then ‘elif’ is tested and there is no Code_1 and again NameError will be raised

  • to repeat process use loop

1 Like

Thanks for helping me. I will use loop to fix my program

Thanks :slight_smile:

While fixing have a look at naming conventions in PEP 8 – Style Guide for Python Code. (Password_1password_1). You could also consider whether you need _1 extension at all and maybe you should use answer instead of user_inputetc.

1 Like