Turn this into a Python program - Improved code with better variable names and error…
- User
Turn this into a Python program
- Improved code with better variable names and error handling
- Declared and initialized variables for escape code, current value, and backup value
- Printed instructions for user to enter escape code
- Prompted user to enter escape code and set it to escape_code variable
- Defined function check_variable that checks and updates the escape_code variable based on user input
- Defined function restore_backup that restores the escape_code variable to its previous value
- Prompted user to either check/update variable or restore backup
- While loop continues until user decides to exit by typing something other than Y or B
- Assistant
Improved code with better variable names and error handling
escape_code = "" current_value = "" backup_value = ""
print("Enter the escape code:") escape_code = input()
def check_variable(escape_code): print(f"The current escape code is {escape_code}.") print("Would you like to update it? (Y/N)") choice = input().upper() if choice == "Y": print("Enter the new escape code:") escape_code = input() print(f"The escape code has been updated to {escape_code}.") elif choice != "N": print("Invalid choice.") escape_code = check_variable(escape_code)
codereturn escape_codedef restore_backup(escape_code, backup_value): escape_code = backup_value print(f"The escape code has been restored to {escape_code}.") return escape_code
print("Would you like to check/update the escape code or restore the backup? (U/R)") choice = input().upper()
while choice == "U" or choice == "R": if choice == "U": backup_value = escape_code escape_code = check_variable(escape_code)
code