String Format Checking in Python
<p>While preparing for my AS-Level Computer Science exam I came across a question in the pre-release material: </p>

<p>Prompt the user to input a User ID and check if the format of the ID corresponds with pre-defined formatting rules and output accordingly.</p>

<p>The Format (In order):</p>

<ol>
<li>One upper case letter</li>
<li>Two Lower case letters</li>
<li>Three numeric characters (digits)</li>
</ol>

<p>Example: "Abc123"</p>

<p>I came up with a solution using my language of choice(Python), however, I was wondering if there is a more elegant or better way to solve this. Especially the third check.</p>

<p>Here is my code:</p>

<pre><code>#Task 2.2

u_id = input("Input User ID: ") #DECLARE u_id : string
numbers = [str(num) for num in range(10)]

#Checking if final 3 characters of User ID (u_id) are digits
for i in list(u_id[3::]):
    if i not in numbers:
        digit_check = False #DECLARE digit_check : bool
        break
    else:
        digit_check = True

#User ID format check
if (u_id[0:1].isupper() == True) and (u_id[1:3] == u_id[1:3].lower()) and (digit_check == True):
    print ("Correct Format")
else:
    print ("Wrong Format")
</code></pre>

<p>Ignore the DECLARATION comments. They are an exam requirement.</p>

<p>Thanks</p>