You should be able to:
Structured programming refers to creating blocks of code made up of:
Advantages are:
The two text files can be download here:
The video below shows my attempt at the solution. If you decide to watch the video then look out for:
This solution isn't perfect and another hour or two of coding would make it an efficient solution.
A good programmer would have...
The Python Code from the Video:
def enterReg(): #user enters the registration lengthCheck = "" first2Letters = "" first2region = "" fthLetterspace = "" second2year = "" lastThree = "" print ("Enter a registration number to authenticate") registration=input().upper() print ("You entered..."+registration) print ("Is this correct? Y / N") answer = input().upper() while answer not in ["Y","N"]: print ("You must enter Y or N") answer = input() if answer == "Y": trueCount=0 print ("Registration Entered") print ("Authentication started") lengthCheck=(checkLength(registration,lengthCheck)) if lengthCheck==True: trueCount+=1 print ("Registration Correct Length: "+str(lengthCheck)) first2Letters=(f2Letters(registration,first2Letters)) if first2Letters==True: trueCount+=1 print ("First two characters are letters: "+str(first2Letters)) first2region=(f2Region(registration,first2region)) if first2region==True: trueCount+=1 print ("The region is valid: "+str(first2region)) second2year=(s2Year(registration,second2year)) if second2year==True: trueCount+=1 print ("The year is valid: "+str(second2year)) fthLetterspace=(fthSpace(registration,fthLetterspace)) if fthLetterspace==True: trueCount+=1 print ("The 5th Letter is a Space: "+str(fthLetterspace)) lastThree=(lstThree(registration,lastThree)) if lastThree==True: trueCount+=1 print ("The last three characters are letters: "+str(lastThree)) if trueCount==6: print ("Registration Number is Authentic") else: print ("Registration Number is Fake") else: enterReg()def quitApp(): #quits the program print ("Are you sure you want to quit? Y / N") answer=input().upper() while answer not in ["Y","N"]: print ("You must type Y or N") answer=input().upper() if answer=="Y": quit() else: menu()def checkLength(registration,lengthCheck): #checks if the reg is the length is 8 characters regLength = (len(registration)) if regLength!=8: lengthCheck=False else: lengthCheck=True return lengthCheckdef f2Letters(registration,first2Letters): #checks the first two are letters checkLetters=[] firstTwo=(registration[0:2]) for letter in firstTwo: alphabet=letter.isalpha() checkLetters.append(alphabet) if checkLetters[0]==True and checkLetters[1]==True: first2Letters = True else: first2Letters = False return first2Lettersdef f2Region(registration,first2region): #checks the first two are in a valid region firstTwo=(registration[0:2]) f = open('validregion.txt', 'r') first2region = False for line in f: lineFirstTwo=line[0:2] if lineFirstTwo==firstTwo: first2region=True return first2regiondef s2Year(registration,second2year): #checks if the second two are a valid year secondTwo=str(registration[2:4]) f = open('validyear.txt', 'r') second2year = False for line in f: lineSecondTwo=str(line[0:2]) if lineSecondTwo==secondTwo: second2year=True return second2year def fthSpace(registration,fthLetterspace): #checks if the fifth letter is a space fthLetter=(registration[4]) if fthLetter == " ": fthLetterspace=True else: fthLetterspace=False return fthLetterspacedef lstThree(registration,lastThree): #checks if the last three are letters three = registration[5:8] letterCount=0 for letter in three: if letter.isalpha(): letterCount+=1 if letterCount == 3: lastThree=True else: lastThree=False return lastThreedef menu(): #menu system print ("Welcome to the License Authentication Application") print ("-------------------------------------------------") print ("Choose an option:") print ("1. Enter a Registration") print ("2. Quit") print ("Enter an option number...") option=input() while option not in ["1","2"]: print ("Enter either 1 or 2") option=input() if option=="1": enterReg() elif option=="2": quitApp() menu()SOURCE RECOGNITION - PLEASE NOTE: The examination examples used in these walking talking mocks are samples from AQA from their non-confidential section of the public site. They also contain questions designed by TeachIT for AQA as part of the publicly available lesson materials.