If Statements
myName = input("What's your name?: ")
if myName == "Dravid":
An Example as a code :-
myName = input("What's your name?: ")
if myName == "Dravid":
print("Welcome Dude!")
If the condition is not met with the if statement, then we want the computer to do the else part instead. Likewise, if the condition is met in the if statement, then the else bit is ignored by the computer. The else statement must be the first thing unindented after the if statement and in line with it.
myName = input("What's your name?: ")
if myName == "Dravid":
print("Welcome Dude!")
print("You're just the baldest dude I've ever seen")
else:
print("Who on earth are you?!")
The elif command (which stands for 'elseif') allows you to ask 2, 3, 4 or 142 questions using the same input! This command must be in a certain place. You can have as many elif statements as you want, but they must go in between if and else and have the same indentation. The print statements in your elif command need to line up with the indent of the other print statements.
An Example as a code :-
print("Secure login into Rude Rows")
userName = input("Tell me your Username:")
password = input("Put your password here:")
if userName == "Ruderows" and password== "abcd" :
print("Hey there",userName)
elif userName == "suman" and password== "efgh":
print("Hey there",userName)
elif userName == "biman" and password== "ijkl":
print("Hey there",userName)
else :
print("Go away")
No comments:
Post a Comment