# IF ELSE ELIF
print('What is age?')
age = int(input('number:')) # user gives number as input
if age > 18:
print('go ahead drive')
elif age == 18:
print('come personaly for test')
else:
print('still underage')
#Conditionals statements in python
#'=' conditionals statements
a = 123
b = 123
if(a==b):
print('True')
#<, > conditionals statements
a = 2
b = 45
if(a<b):
print('A is smaller than B')
#if else loop in python
#simple example
age = int(input("What is your age: "))
if age < 18:
print("You can't vote")
#if you enter your age less than 18 it will print you can't vote
else:
print("you can vote")
#if you enter your age greater than 18 it will print you can vote
# IF ELSE ELIF
age=int(input("Enter your age:"))
if age<=18:
print("sorry your are not eligible for vote")
elif age>=18:
print("u are eligible for vote")
else:
print("in some how the previou's condition fails else part will run")
# plz suscribe to my youtube channel -->
# https://www.youtube.com/channel/UC-sfqidn2fKZslHWnm5qe-A
#if else conditions in python
a = "if else conditions are inportant"
if "else" in a:
print("Word is in a")
else:
print("word is not in a")
answer = input(":")
if answer == "lol":
print("haha")
else:
print("not haha")
exit()
please note that the exit() command is optional and is not necessary.
word = input('Word: ') # This will ask you to print a word
if word == 'hello': # <- If your response is: 'hello'
print('world') # <- It will output: 'world'
elif word == 'world': # If the response is: 'world'
print("Hey, that's my line >:(") # It will print this
else:
print("Hey buster you gonna say hello or not?")
# If sombody prints ANYTHING ELSE other than 'hello' or 'world'
# It will output that print statment above!
#Hope this helped you!
# plz suscribe to my youtube channel -->
# https://www.youtube.com/channel/UC-sfqidn2fKZslHWnm5qe-A
print("Welcome to Rolercoster rider")
print()
#taking input of your hight
Your_hight = int(input("What is Your hight:- "))
#if condition
if Your_hight >= 120:
print("You are good to go to the roller coster")
else:
print("Grow taller to go to the rolercoster")
# How conditions work
if condition:
# if condition met
# code here
elif condition2: # (else if) checked if the first condition is false
# if condition2 met
# code here
elif condition3: # elif can be chained
# if condition3 met
# code here
else:
# if none of the conditions are met
# code here
# example
if name == "bob": # ex. a == b (is a equal to b)
print("the wifi password is 1234")
elif name == "jake": # if the first condition is not met python checks this one
print("the secret formula is under the bed")
else: # if none of the conditions are met
print("sorry i don't know who you are")
# Other Example
if age >= 18:
print('You can go in')
else:
print('you cannot pass, you are underage')
can_do = True
can_do1 = True
if can_do:
print("we can do it")
elif can_do1:
print("we can do it but the second time")
else:
print("we cant do it")
#result should be (we can do it.)
x = int(input("number: ")) # get number from user
if x < 0:
print(f"{x} is less than 0!") # if x is less than 0, print x is less than 0
elif x == 0:
print(f"{x} is equal to 0!") # if x is equal to 0 then print x is equal to 0
if x > 0:
print(f"{x} is more than 0!") # if x is greater than 0 print x is more than 0
# yeah its me somewhatoriginal
user_info = input("How may I help you?: ")
if user_info == "on":
print("Light is Turned Om")
elif user_info == "off":
print("Light is turned Off")
elif user_info == "status":
input("All are Good.What do you need?: ")
print("I don't have it")
else:
print("Shutdown processing are being Ready")
#copy the code to your py script to have the results!!!
temperature = float(input('What is the temperature? '))
if temperature > 70:
print('Wear shorts.')
else:
print('Wear long pants.')
print('Get some exercise outside.')
can_run = True
can_run2 = False
if can_run:
print("i can run the code because can_run is true")
elif can_run2:
print("i can run the code if can_run2 is true")
else:
print("no other bool found true")
#result should be (i can run the code because can_run is true
number = int(input("Enter a number from 1 to 3"))
# make the user write a random number from 1 to 3
if number == 1:
print("You choose number 1")
elif number == 2:
print("You choose number 2")
else:
print("You choose number 3")
water = input('Does your creature live underwater?')
if water == 'yes':
print('Your creature lives underwater')
else:
print('Your creature does not live underwater')
boolean1 = (1 != 1)
boolean2 = (2 + 2 == 5)
boolean3 = (1 == 1)
if (boolean1):
print("Boolean one is true")
elif (boolean2):
print("Boolean two is true")
else:
print("Boolean three may, or may not be true")