An if-else statement

In the preceding example, we used an if statement to test each condition. In Python, there is an alternative option named the if-else statement. The if-else statement enables testing an alternative condition if the main condition is not true:

check_address = input("Is your address correct(yes/no)? ") 
if check_address == "yes":
print("Thanks. Your address has been saved")
else:
del(address)
print("Your address has been deleted. Try again")

In this example, if the user input is yes, the indented code block under if is executed. Otherwise, the code block under else is executed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.10.137