DEV Community

Abdur-Rahman
Abdur-Rahman

Posted on

Driving Age Calculator (NC) in Python

Hey there! Today, I'm excited to share with you a Python script I and some other young developers created to help drivers in North Carolina (NC) determine their eligibility for obtaining a driver's permit or license.

Getting Started

Before we dive into the code, make sure you have Python installed on your computer. You can easily download the latest version from the official Python website.

You can also register for an account at Replit if you are not able to download Python on your computer.

To create a safe environment for our users, I've added a password feature that you can customize. Users need to enter the correct password to access the calculator and determine their driving eligibility. This ensures that only those who have the correct password can use the tool.

The Code

# Passwords
password = str(input("Choose a password! Make it really strong! > "))
password = password.lower()

age = int(input("How old are you? Please type numbers only because it will throw an error. > "))
# Conditionals for Age in license
psswd = str(input("Enter your Password: > "))
psswd = psswd.lower()
authenticated = False
if psswd == password:
  print("You are authenticated.")
  authenticated = True
else:
  print("Wrong password. Stop hacking.")
  authenticated = False

while authenticated:
  # Age-based conditions for driving privileges
  if age == 14:
    # Information for obtaining a driver's permit
    print("Great news! You are ready to obtain your driver's permit!")
    print("Go to https://www.ncdot.gov/dmv/license-id/driver-licenses/Pages/default.aspx to learn about obtaining your permit!")
    authenticated = False

  elif age >= 15 and age <= 17:
    # Checking if the user has a permit or needs to get one
    license = input("Do you have a permit? > ").lower()
    if license == "yes":
      print("Keep driving & learning!")
    elif license == "no":
      print("You need to go to driving school and obtain your permit!")
      print("Check out the NC website for more instructions: https://www.ncdot.gov/dmv/license-id/driver-licenses/Pages/default.aspx")
      authenticated = False
    else:
      print("You typed the wrong response. Please type 'yes' or 'no'.")
      authenticated = False

  # More age-based conditions for different driving privileges
  # [Add code for age groups 18-20 and 21 and older]

  else:
    print("You typed the wrong response. Please type 'yes' or 'no'.")
    authenticated = False
    break
Enter fullscreen mode Exit fullscreen mode

How it Works

The script starts by asking the user to set a custom password. This password is used to authenticate the user and ensure that only authorized individuals can access the driving age calculator. After entering the password, users are prompted to enter their age.

Based on the provided age, the script employs a series of conditional statements to determine the appropriate driving privileges for the user. For example, if the user is 14 years old, the script provides information on obtaining a driver's permit. Similarly, for ages between 15 and 17, the script checks if the user already has a permit or needs to obtain one by attending driving school.

Conclusion

And there you have it – a Python-based Driving Age Calculator for North Carolina! This simple tool empowers users to understand the age requirements for different driving privileges, making it easier for young drivers to navigate the process of obtaining their permits and licenses.

Feel free to check out the complete code on Replit. If you find this script helpful, don't forget to share it with your friends and fellow developers.

Safe driving and happy coding! 🚗💻

P.S. This driving calculator is based on North Carolina's laws. If you find any errors or have any suggestions, feel free to leave a comment explaining.

Top comments (0)