Conditional Statement is a very important concept in computer programming as well as in Python.
Let’s check out some exercises that will help understand Conditional Statements (if-elif-else) better.
Write an if statement that asks for the user's name via input() function. If the name is "Bond" make it print "Welcome on board 007." Otherwise make it print "Good morning NAME". (Replace Name with user's name)
input() function will return the input from the user.
name = input(“Please enter your name.”)
An if – else statement will achieve what you need.
if name == xx:
statement1
else:
statement2
Make sure to note logical operators can be slightly different than mathematical operators in Python (i.e.: “==” instead of “=”)
name = input("Please enter your name.")
if name == "Bond":
print("Welcome on board 007.")
else:
print("Good morning " + name)