The Student Room Group

Computer Science GCSE question

(In Python) to check if a license plate is real the first two letters and the third and fourth letters should be letters and the third, fourth seventh and eights are numbers. I need to design a programme to do this, can anyone help please....
Hi, JoPerkins!

I won't tell you everything, because that hardly helps. The first thing you'll need to do is import the regular expression module (specifically, the .search() function), then declare a variable (say, license_plate) to be assigned a user-determined value (i.e. their license plate):

import re
license_plate = str(input("Enter your license plate: "))

Hopefully you can figure out the rest of this on your own! If not, I do have a program in the spoiler, but please don't look unless you're really stuck! I did have to use an emulator, however, so it's possible that my code is actually broken. Hopefully not, though!

Spoiler



Hope this helps!

Yours,
Grey
Reply 2
Thanks, I will give it a try
Original post by JoPerkins
(In Python) to check if a license plate is real the first two letters and the third and fourth letters should be letters and the third, fourth seventh and eights are numbers. I need to design a programme to do this, can anyone help please....



This is only pseudo code as I am too lazy to lookup the correct syntax.

plate = string(input("Enter license plate"))
letters = array(abcdefgh.....)
number = array(123456.....)

if plate[0] or plate[1] is not in letters{
print bad
return false
}

then repeat for each part, remember index numbers.

Quick Reply

Latest

Trending

Trending