Use Boolean True or False in Python programming

python_bg

Here’s an example of my script that:  Creates a new list based on car numbers, only with a value above 1,  or else reports that none are available. I am by no means a programmer and this is my first day of Python language training (all these posts are for personal reference!)

				
					#the car numbers
my_car_numbers = [ 1, 2, 21, 2, 1, 4, 3, 6, 7]

#new car list generated from above car_numbers_list if true
my_car_list = []

#list all the card with numbers above 1 and put them on the my_car_list and print this.
for carnumber in my_car_numbers:
    if carnumber > 1:
        my_car_list.append(carnumber)

if my_car_list:
    print(my_car_list)

#if no car above 1 is available, output the message below
else:
    print("There are no cars on the list with a value above 1")
				
			

 

Output of the script above:

				
					└──$ python3 boolean_true_or_false.py 
[2, 21, 2, 4, 3, 6, 7]
				
			
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
python_bg

Use string formatting in Python programming

Next Post
Android APK

Create a backdoor in Android APK file

Related Posts