简体   繁体   中英

How can i make this for random 6 digit number

from pynput import keyboard
from pynput.keyboard import Controller, Key
import itertools
import time

keyboard = Controller()

for i in reversed(range(5)):
    print(i)
    time.sleep(1)

for combination in itertools.product(range(10), repeat=6):
    laina = (''.join(map(str, combination)))

    keyboard.type(laina)
    keyboard.press(Key.enter)
    keyboard.release(Key.enter)
    keyboard.press(Key.ctrl)
    keyboard.press('a')
    keyboard.release('a')
    keyboard.release(Key.ctrl)
    time.sleep(0.3)

You can get a random 6-digit integer with random.randint(0, 999999).

If you need your value x padded with left zeros to make a six-digit string, then use f"{x:06d}".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM