반응형
[python] Generate OTP using python
Here’s how you can generate a one-time password (OTP) using Python:
import random
def generate_otp(length=6):
"""
Generates a numeric OTP of the given length.
Default length is 6.
"""
if length <= 0:
raise ValueError("Length must be greater than zero")
otp = ''.join([str(random.randint(0, 9)) for _ in range(length)])
return otp
# Example usage
otp = generate_otp(6)
print(f"Your OTP is: {otp}")
Your OTP is: 583920
반응형
'프로그래밍 > Python' 카테고리의 다른 글
[python] pair plot (1) | 2024.12.20 |
---|---|
[python] Rich is a Python library for rich text and beautiful formatting in the terminal. (0) | 2024.12.11 |
[python] Code: Turtle Yellow Heart on Black Background (0) | 2024.12.06 |
[python] Spiral Web using Matplotlib and NumPy (0) | 2024.12.03 |
[python] 초를 입력 받으면 카운트다운 하는 간단한 타이머 (0) | 2024.12.02 |