Even and Odd Number Algorithm in Python Programming Language
Noah Olatoye

Noah Olatoye

90

Even and Odd Number Algorithm in Python Programming Language

You won't believe this!

A colleague of mine met me yesterday just before we closed for the day, and he said to me:

"Boss, you said you're going to assign the marketing lead to us. Are we still getting that today?"

I responded, "yes, you are". 

Practically, it's not possible that evening (because we're talking about over 500 submitted contacts here...). 

While it isn't possible to manually achieve all of the tasks the same evening (of course, I was too tired to go through the 500 contact list), programmatically, it is possible. 

I just told my colleague to check back in a few minutes.

Just for a few minutes, I came up with logic that could do the updates for me in seconds. 

Although I wrote the logic for just a shortlist of 500 entries (which might look small), these same 16 lines of code can perform the same task on millions of entries in seconds without me moving an inch.

Ask the computer to do it for you whenever you feel something is too redundant. 

Code snippet with Python Programming Language:

 


from marketing.models import KidsCanCode  # Import your data table
from django.contrib.auth.models import User # Import the staff

Grab the KidsCanCode table and assign to staff



def update_marketing_field():

p = KidsCanCode.objects.filter(timestamp__year='2021', timestamp__month='11')

timothy = User.objects.get(username='BlueTimothyOsadebeb')

ods = User.objects.get(username='ODS')

count = 0




for pa in p:<br />
    if (count % 2) == 0:  # Check if there is no remainder<br />
        pa.staff = timothy<br />
    else:<br />
        pa.staff = ods<br />
    pa.save()<br />
    count += 1</code></pre>

A tech career with instinctHub

Ready to kickstart your tech career or enhance your existing knowledge? Contact us today for a dedicated instructor experience that will accelerate your learning and empower you to excel in the world of technology.

Our expert instructors are here to guide you every step of the way and help you achieve your goals. Don't miss out on this opportunity to unlock your full potential. Get in touch with us now and embark on an exciting journey towards a successful tech career.

Add Comments

First Name
Last Name
Say something:

Are you human? Solve this:

+ = ?

Post you may also like