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

AI Thread Summary
The discussion centers around a Python code snippet that uses conditional statements to categorize age. It highlights how boolean values and comparisons are essential for controlling program flow with if, elif, and else statements. The example provided, while deemed confusing by some, serves to illustrate how these comparisons yield True or False outcomes that dictate the program's behavior. There is a suggestion that the complexity may arise from the timing of introducing functions in learning materials. The conversation also emphasizes the value of self-learning in Python, with participants sharing experiences of trial and error, utilizing resources like StackExchange, and reviewing others' code to enhance their understanding.
shivajikobardan
Messages
637
Reaction score
54
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")

https://www.fullstackpython.com/blog/python-basic-data-types-booleans.html
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.
 
Technology news on Phys.org
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.
 
exactly very confusing example. I am tired of self learning. always stumbled upon these types of things.
 
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.
 
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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

Similar threads

Replies
1
Views
3K
Back
Top