How would you generate and store a unique ID to a text file based off of a user input?
<p>I'm looking to use user input names to create a unique ID for registration purposes. First, in the code, I ask them for both of their names:</p>

<pre><code>    Forename = str(input("Enter your first name: "))
    Surname = str(input("Enter your surname: "))

    (UID) = Forename[0], Surname[0],"0000"
    print (UID)
</code></pre>

<p>However, I want this saved to a text file (or into access) and if the last 4 numbers are taken, the number should be increased by 1.</p>

<p>For example, if Joe Bloggs is the first register, their UID will be JB0000. Then, if Stephen User signs up after, their UID will be SU0001. I've been trying various methods of trying to increase the UID[2:]+1 but it doesn't seem to work... Any help would be appreciated.</p>

<p>As a starting point I'd suggest something like this:</p>

<pre><code># input returns type `str` so we do not need to cast this manually to string
first_name = input("Enter your first name: ")
name = input("Enter your surname: ")

# let's assume there are already three users
# you need to implement a own routine to determine this number later
number_of_active_users = 3

# create the user number
user_number = str(number_of_active_users+1).zfill(4)

# determine the user's initials
user_name = first_name[0] + name[0]

# glue everything together
uid = user_name + user_number

print(uid)
</code></pre>

<p>For user <code>Albert Emil</code> this would return:</p>

<pre><code>AE0004
</code></pre>

<p>However, this snippet is just a quick 'n' dirty approach. There is a much nicer way to do this using the string formatting mini language.</p>

python