Python What does this code signifies in relation to boolean logic?

shivajikobardan

Junior Member
Joined
Nov 1, 2021
Messages
107
Code:
my_age = 10

if my_age >= 100:
  print("One hundred years old! Very impressive.")
elif my_age <= 3:
  print("Awwww. Just a baby.")
else:
  print("Ah - a very fine age indeed")


Article says-:
Booleans are used in your code to make it behave differently based on current conditions within your program. You can use boolean values and comparisons in conjunction with the if, elif, and else keyoards as one means to achieve this.
 
Code:
my_age = 10

if my_age >= 100:
  print("One hundred years old! Very impressive.")
elif my_age <= 3:
  print("Awwww. Just a baby.")
else:
  print("Ah - a very fine age indeed")


Article says-:
Please show us what you have tried and exactly where you are stuck.

Please follow the rules of posting in this forum, as enunciated at:


Please share your work/thoughts about this problem.
 
The expressions highlighted below are boolean. The >= and <= comparison operators return a boolean value, ie True or False.
Rich (BB code):
my_age = 10

if my_age >= 100:
  print("One hundred years old! Very impressive.")
elif my_age <= 3:
  print("Awwww. Just a baby.")
else:
  print("Ah - a very fine age indeed")

FYI: You can also assign such a boolean expression to a variable, and use a boolean variable in an "if" statement. For example...
Python:
is_over_99 = my_age >= 100

if is_over_99:
  print("One hundred years old! Very impressive.")
...
 
Top