In python TASK ONE – Build a function that gets the required information from the user…
- User
In python TASK ONE – Build a function that gets the required information from the user and stores it in your data structure of choice. This includes their: · First name · Middle name · Surname · Gender · Birth day · Birth month · Birth year TASK TWO – Introduce data validation to your TASK ONE function; the user should not be allowed to enter erroneous input, such as blank input or a number instead of a first name. TASK THREE – Build a function that generates characters 1-5 and characters 12-13. TASK FOUR – Build a function that generates characters 6, 7-8, 9-10 and 11. TASK FIVE – Build a function that generates characters 14 and 15-16. TASK SIX – Build a function that assembles the final driver’s license and outputs it for the user. based offf.. Figure 1 Character(s) Requirement 1-5 First five characters of the driver’s surname. If the surname is shorter than 5 characters long, any leftover characters are filled up with 9s (e.g, LEE99). 6 The decade digit from the driver’s birth year (e.g, 7 in 1973). 7-8 The driver’s birth month, 01-12. For female drivers only, the seventh character is incremented by 5, 51-62. 9-10 The driver’s birth day, 01-31. If the birth month is February, this range is 01-28, and if the birth year is a leap year, it is 01-29. 11 The year digit from the driver’s birth year (e.g, 3 in 1973). 12-13 The first character from the driver’s first name and the first character from the driver’s middle name. If the driver has no middle name, the character is replaced with a 9. 14 A random digit, typically 9. This is to avoid having drivers with duplicate details. If a new driver with the same details applies, this digit is reduced by 1 and 9 becomes 8, 8 becomes 7 and so on. You can assume there will be no duplicate drivers. 15-16 Two random letters A-Z.
- Assistant
import random def user_input(): first_name = input("Enter your first name: ") middle_name = input("Enter your middle name (leave blank if none): ") surname = input("Enter your surname: ") gender = input("Enter your gender (M/F): ") birth_day = int(input("Enter your birth day (1-31): ")) birth_month = int(input("Enter your birth month (1-12): ")) birth_year = int(input("Enter your birth year (e.g. 1998): ")) user_info = { "first_name": first_name, "middle_name": middle_name.strip(), "surname": surname, "gender": gender, "birth_day": birth_day, "birth_month": birth_month, "birth_year": birth_year, } return user_info def task_one(): info = user_input() first_five_characters = info["surname"].upper()[:5] decade_digit = str(info["birth_year"])[2] month_char = str(info["birth_month"]).zfill(2) if info["gender"].upper() == "F": month_char = str(int(month_char) + 50) day_char = str(info["birth_day"]).zfill(2) second_char = info["first_name"][0].upper() if info["middle_name"]: third_char = info["middle_name"][0].upper() else: third_char = "9" last_digits = "".join(random.choices("ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789", k=3)) license_number = ( first_five_characters + decade_digit + month_char + day_char + second_char + third_char + last_digits ) return license_number print(task_one())
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.