1print("Welcome to Rolercoster rider")
2print()
3#taking input of your hight
4Your_hight = int(input("What is Your hight:- "))
5#if condition
6if Your_hight >= 120:
7 print("You are good to go to the roller coster")
8else:
9 print("Grow taller to go to the rolercoster")
1# IF ELSE ELIF
2
3print('What is age?')
4age = int(input('number:')) # user gives number as input
5if age > 18:
6 print('go ahead drive')
7elif age == 18:
8 print('come personaly for test')
9else:
10 print('still underage')
11
1The elif statement allows you to check multiple expressions for TRUE
2and execute a block of code as soon as one of the conditions evaluates
3to TRUE. Similar to the else, the elif statement is optional. However,
4unlike else, for which there can be at most one statement, there can
5be an arbitrary number of elif statements following an if.
6
7if expression1:
8 statement(s)
9elif expression2:
10 statement(s)
11elif expression3:
12 statement(s)
13else:
14 statement(s)
15
1#if else conditions in python
2a = "if else conditions are inportant"
3if "else" in a:
4 print("Word is in a")
5else:
6 print("word is not in a")
7
1variable_name = input("y/n? >> ")
2if variable_name == "y":
3 print("That's good! :) ")
4# note the double equal signs. only a single equal sign will receive a Syntax error blah blah blah message.
5elif variable_name == "n":
6 print("That's bad! :( ")
7else:
8 print("You blow up for not following my instructions. Detention forever and get lost!")
1# The If and Elif statements in python check if a condition is true.
2# If it is, it will run the code inside of the if/elif block.
3# Elif is short for else if.
4# The else statement is used if none of the conditions are true.
5# Here's an example of if, elif and else:
6
7num = int(input('Enter a number, either one, two or three. '))
8if num == 1:
9 print('The number is 1.')
10elif num == 2:
11 print('The number is 2.')
12elif num == 3:
13 print('The number is 3.')
14else:
15 print('Invalid input.')