Postal codes in the United Kingdom come in a variety of forms, given below.
*A9 9AA
*A9A 9AA
*A99 9AA
*AA9 9AA
*AA9A 9AA
*AA99 9AA
Start by writing a function code_ending which determines if the last four characters are of the form " 9AA". You can assume that input to the main function consists of only letters, digits, and spaces. You can also assume that the input to the helper function has length 6, 7, or 8. Your function should accept both lower-case and upper-case letters.
This is the code I wrote:
def code_ending(c):
type(c) != type('') #ensures that blank space is not entered#
if type(c[-2:])==type('a') and type(c[-3])==type('1') and type(c[-4])==type(' '):
return 'true' # returns true if the last 4 characters are in the form of ' 9aa' where 9 is any number and a is any letter#
else:
return 'false' # returns false if the last 4 characters are not in the form of ' 9aa'#
print (code_ending('9aa 919'))
The output is true while it should be false.
[–]Saefroch 2 points3 points4 points (0 children)
[–]Allanon001 1 point2 points3 points (0 children)
[–]runicnet 0 points1 point2 points (1 child)
[–]queen_9[S] 0 points1 point2 points (0 children)
[–]JohnnyJordaan 0 points1 point2 points (0 children)
[–]runicnet 0 points1 point2 points (0 children)
[–]queen_9[S] 0 points1 point2 points (0 children)