Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding Improvement
#1
Trying to make completion time faster and stable, anyone have better code for that?

Here is my try

import time

def find_pin(pin):
    start_time = time.time()
    pin_int = int(pin)
    for guess in range(1000000):
        if guess == pin_int:
            end_time = time.time()
            print(f"PIN found: {guess:06}")
            print(f"Completion time: {end_time - start_time} seconds")
            break

# Example usage:
pin_input = input("Enter a 6-digit PIN: ")
find_pin(pin_input)
buran write Mar-21-2024, 02:41 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
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