I'm very much new to Stackoverflow and Python(3) so excuse any errors I've made! This is the code I wrote so far:
print("""You will need to enter your name so we can make a reservation!
(Use Enter ↵ to confirm)""")
user_firstname = str(input("What is your first name? "))
user_lastname = str(input("What is your last name? "))
confirm_username = str(input("Is your name " + user_firstname + " " + user_lastname + " ? (y/n) "))[0]
while not confirm_username == "y":
user_firstname = str(input("What is your first name? "))
user_lastname = str(input("What is your last name? "))
confirm_username = str(input("Is your name " + user_firstname + " " + user_lastname + " ? (y/n) "))[0]
else:
user_name = user_firstname + " " + user_lastname
As you can see in my example I have to state some variables twice (user_firstname, user_lastname & confirm_username). Once before the while loop and once within the while loop. I was wondering if there is a more elegant, less bulky way of writing this code? Any other optimization suggestions are very much welcome as well!
Thank you!