Welcome to our community

Be a part of something great, join today!

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

shivajikobardan

New member
Nov 12, 2021
12
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.
 

Jameson

Administrator
Staff member
Jan 26, 2012
4,058
This is a weird example, I agree, but I think their idea is that the comparisons will resolve to True/False booleans which will then dictate the conditional flow.
 

shivajikobardan

New member
Nov 12, 2021
12
exactly very confusing example. I am tired of self learning. always stumbled upon these types of things.
 

Evgeny.Makarov

Well-known member
MHB Math Scholar
Jan 30, 2012
2,562
What is confusing about it? If you don't like it, consider this:
Python:
def age_class(my_age):
  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")
and a call age_class(10) to the interpreter. Maybe by the time this example is encountered the course has not covered functions yet, and the authors want to provide a code fragment that compiles and runs correctly.
 

Jameson

Administrator
Staff member
Jan 26, 2012
4,058
I think self-learning for Python is actually much better than formal courses. I've spent the last 2 years focused heavily on Python and a lot of it is just trial and error, reading StackExchange, and reading others' code. Happy to take a look at more of these questions though.