create true or false row based on if else condition in python

You can use the if else condition to create a True or False row in Python. Here's an example:

main.py
# Create a list of numbers
numbers = [4, 9, 16, 25, 36]

# Create an empty list to store True or False values
tf_row = []

# Loop through the list of numbers
for i in numbers:
    # Check if the number is greater than 15
    if i > 15:
        # If the number is greater than 15, append True to tf_row
        tf_row.append(True)
    else:
        # If the number is less than or equal to 15, append False to tf_row
        tf_row.append(False)

# Print the True or False row
print(tf_row)
490 chars
19 lines

This will output:

main.py
[False, False, True, True, True]
33 chars
2 lines

In this example, we create a list of numbers [4, 9, 16, 25, 36] and an empty list tf_row. We then loop through the list of numbers and check if each number is greater than 15. If it is, we append True to tf_row, otherwise we append False. Finally, we print the true or false row [False, False, True, True, True].

related categories

gistlibby LogSnag