Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding Improvement
#6
(Mar-26-2024, 03:57 PM)MoreMoney Wrote: Thank you for your help, but i have question i just need 6 atm digit for my homework should i decrase the range for faster completion time, or they dont make any different? Thank you

Also how to install numba properly?
It was more a example on how to speed up code a lot,i don't think you should give Numba code as a solution.
Without the ability to use external libraries or multiprocessing,and given the straightforward nature of a brute-force search,
there are limitations to how much the efficiency of this algorithm can be improved with pure Python.
Can clean it up a little.
from time import time

def find_pin(target_pin):
    for guess in range(1000000):
        if guess == target_pin:
            return True
    return False

def valid_pin(pin):
    return pin.isdigit() and len(pin) == 6

pin_input = input("Enter PIN: ")
start = time()
if not valid_pin(pin_input):
    print("Entered PIN is invalid")
else:
    target_pin = int(pin_input)
    if find_pin(target_pin):
        print(f"Found PIN in {time() - start} seconds.")
    else:
        print("PIN not found.")
Numba you install with pip.
MoreMoney likes this post
Reply


Messages In This Thread
Coding Improvement - by MoreMoney - Mar-21-2024, 11:12 AM
RE: ATM PIN Coding Improvement - by deanhystad - Mar-21-2024, 09:33 PM
RE: ATM PIN Coding Improvement - by MoreMoney - Mar-24-2024, 10:45 AM
RE: Coding Improvement - by snippsat - Mar-24-2024, 11:49 PM
RE: Coding Improvement - by MoreMoney - Mar-26-2024, 03:57 PM
RE: Coding Improvement - by snippsat - Mar-26-2024, 05:58 PM
RE: Coding Improvement - by MoreMoney - Mar-27-2024, 01:03 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020