How to find Odd minute from the current time using Python?

From today lesson, we will learn how to find the odd minute from the current time using Python script. And you will know how to extract the minute from the current date/time and if / else condition in Python.

Create a Python script

# importing the datetime library 
from datetime import datetime
# initialize the odd numbers
odds = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19,
       21, 23, 25, 27, 29, 31, 33, 35, 37, 39,
       41, 43, 45, 47, 49, 51, 53, 55, 57, 59]
# get current minute
current_minute = datetime.today().minute
# check the odd minute
if current_minute in odds:
    print("Odd minute.")
else:
    print("Not an odd minute.")

That’s it. I hope this will help. ?
Photo: https://www.brandeps.com

Leave a Reply

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