Reputation: 59
I am a total amateur when it comes to python and I have came across an issue:
if input() == existingUsername:
print('Sorry, that username is taken, please try again:')
However, I need to access exisingUsername before it is declared, because I've defined it at the bottom of my code. I know you can do this in javascript with the let variable, but how can I do it in python?:
let existingUsername;
//code
existingUsername = 'name'
Upvotes: 1
Views: 985
Reputation: 372
You can't use a variable before declaring it. You could however use an empty string:
existingUsername = ""
# .
# .
# the rest of your program
# .
# .
username = input()
if username == existingUsername:
print('Sorry, that username is taken, please try again:')
else:
# assign new username here
existingUsername = username
Upvotes: 3