We often need to do one thing if a condition is true and a different thing if it is false. To do this we do the if as before but provide a second indented piece of code that is executed only when the condition is false.
if username == "Anne":
print("Welcome, Anne")
else:
print("Go away, I don't know you.")
Just like before this program will print 'Welcome, Anne' if username is equal to Anne. It will then skip over the else and the second indented section.
However, if username is not equal to Anne the program will skip the first indented section to the else line and then run the second indented section. It will now print 'Go away, I don't know you.' rather than just doing nothing.
Note that we don't need to test anything with the else. The program will only get to the else line if the first condition is not true, so it would be pointless to test to see if username is not equal to Anne. We know username is not equal to Anne because if it were equal to Anne it would have done the first bit of code and skipped over this bit.
There are many situations where there two different outcomes and some criteria that decides which will happen.
Does the person want sugar in their tea? Yes - ask how many sugars. No - pass them the tea
Did your basketball shot go through the basket? Yes - celebrate wildly. No - hang your head as you trudge back to your end of the court.
Is your attack roll higher than their armour class? Yes - roll for damage. No - you miss?
Sometimes there are more than just two outcomes and that's where we need elif.
If Else Part 1 - Giving the program something else to do