The if-else construct allows us to execute some block of code if a condition is True, otherwise execute some other block of code.
One of the two code blocks will always execute. It’s just a question of which one.
Note that the program is case-sensitive. “Bob” must be entered with an uppercase “B” to be identified.
name = input("Enter your name: ")
if name == 'Bob':
print("Hello Bob!")
else:
print("You're not Bob!")
print("Where is Bob?")
Enter your name: Bob
Hello Bob!
Enter your name: Clare
You're not Bob!
Where is Bob?
Leave a Reply