#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')
answer = input(":")
if answer == "lol":
print("haha")
else:
print("not haha")
exit()
please note that the exit() command is optional and is not necessary.
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
# If the number is positive, we print an appropriate message
num = 3
if num > 0:
print(num, "is a positive number.")
print("This is always printed.")
num = -1
if num > 0:
print(num, "is a positive number.")
print("This is also always printed.")
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")
num = 1
if num == 1:
print("num is 1"))
elif num == 2:
print("num is 2")
else:
print('invalid number')
# output num is 1
# if the conditional is true the left side of side the expression is resolved else the right side is resolved
print("num is 2") if num == 2 else print("num is 1")
# output num is 1
usrinput = input('Type a number')
if usrinput = 5
print('Your number is equal to 5')
elif usrinput > 5
print('Your number is bigger than 5')
elif usrinput < 5
print('Your number is less than 5')