JoPerkins
Badges: 0
Rep:
?
#1
Report Thread starter 5 years ago
#1
(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....
0
reply
ThenameisGrey
Badges: 6
Rep:
?
#2
Report 5 years ago
#2
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:
Show

import re
license_plate = str(input("Enter your license plate: "))
license_plate_rule = "[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z] [0-9][0-9][0-9]"
if re.search(license_plate_rule, license_plate):
....print("Correct license plate!")
else:
....print("Incorrect license plate!")


Hope this helps!

Yours,
Grey
0
reply
JoPerkins
Badges: 0
Rep:
?
#3
Report Thread starter 5 years ago
#3
Thanks, I will give it a try
0
reply
joshmiller94
Badges: 4
Rep:
?
#4
Report 5 years ago
#4
(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.
1
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Should there be a new university admissions system that ditches predicted grades?

No, I think predicted grades should still be used to make offers (598)
33.92%
Yes, I like the idea of applying to uni after I received my grades (PQA) (735)
41.69%
Yes, I like the idea of receiving offers only after I receive my grades (PQO) (351)
19.91%
I think there is a better option than the ones suggested (let us know in the thread!) (79)
4.48%

Watched Threads

View All