I'm just coding something for fun right now and I'm stuck on looping. I'm using a while loop that only runs if my variable is 0. Right now, I set the variable to 0 but the code was after the loop. How do I fix this?
import time
import sys
#Global Variables
firstTime = True
loggedIn = False
incorrectLogin = True
admin = False
n = 0
n1 = 0
#Create login if firstTime is True
if firstTime is True:
print("Welcome new user!")
time.sleep(1)
print("It looks like it's your first time using this program!")
time.sleep(1.5)
User = input("Please create a user: ")
User_password = input("Please create a password: ")
time.sleep(1)
firstTime = False
#Cosmetic
print("Please log in")
time.sleep(1)
#Login code
while n == 0:
if incorrectLogin is True:
User_input = input("Please input user: ")
if User_input == User:
User_password_input = input("Please input password: ")
#int(User_password_input)
if User_password_input == User_password:
print("Welcome, " + User + "!")
loggedIn = True
incorrectLogin = False
n += 1
else:
print("Incorrect Password!")
incorrectLogin = True
loggedIn = False
else:
print("Incorrect User!")
incorrectLogin = True
loggedIn = False
#If want to set User as admin
askAdmin = input("Would you like to set, "+ User + " as admin? (Y/n) ")
if askAdmin.lower() in ["Y", "y"]:
adminPass = input("Please set up a admin password: ")
print("Setting "+ User + " as admin...")
time.sleep(1)
print("Done!")
User_admin = User
admin = True
n1 += 1
elif askAdmin.lower() in ["N", "n"]:
print("Skipping...")
time.sleep(1)
print("No admin on system.")
admin = False
n1 += 1
#When the user is logged in
while n1 == 1:
if loggedIn == True:
sysInfo = input("1. Who is using the system" \
" 2. Shutdown"
" 3. Is there an admin"
" 4. Change User password"
" 5. Admin panel"
" 6. Log out")
if sysInfo.lower() in ["exit", "Exit", "EXIT"]:
sys.exit()
elif sysInfo.lower() == "1":
print(User)
elif sysInfo.lower() == "2":
print("Shutting down...")
sys.exit()
elif sysInfo.lower() == "3":
if admin == True:
print("The admin on the system is: "+ User_admin)
else:
print("There is no admin on the system!")
elif sysInfo.lower() == "4":
if admin == True:
print("Admin on System detected!")
time.sleep(1)
askAdminPass = input("Please input admin password: ")
if askAdminPass != adminPass:
print("Incorrect Password!")
else:
newUserPasswordWAdmin = input("Please enter new password: ")
User_password = newUserPasswordWAdmin
time.sleep(1)
print("New password set!")
else:
newUserPassword = input("Please enter new password: ")
User_password = newUserPassword
time.sleep(1)
print("New password set!")
elif sysInfo.lower() == "5":
if admin == True:
print("Welcome to the admin panel!")
time.sleep(0.5)
print("There is nothing to do here yet!")
else:
print(User + " does not have admin privileges!")
elif sysInfo.lower() == "6":
print("Signing out...")
time.sleep(1.2)
print("Done!")
incorrectLogin = True
n = 0
n1 = 0
loggedIn = False