Question: Canadian postal codes are alphanumeric in the format A1A 1A1, where A is a letter and 1 is a digit. This makes them awesome

Canadian postal codes are alphanumeric in the format A1A 1A1, where A

Canadian postal codes are alphanumeric in the format A1A 1A1, where A is a letter and 1 is a digit. This makes them awesome for people who like read and write leet (the provided test cases contain some fun examples-the last one is the postal code Canadians use to write to Santa Claus), bu is less awesome for Canadians who want to buy gasoline in the US. To use a credit card to pay at the pump when purchasing gasoline in the US, a Canadian has to convert their postal code to a five-digit number compatible with the US zip code format. To do this, they are instructed to remove all the non-digits, and then add zeroes to the end to make it five digits long. You have the great idea to make a fortune by writing a mobile app to assist Canadians with this difficult task and sell it for $0.99 (CAD Below is a function named canada_to_us () that accepts a single parameter: a string containing a valid Canadian postal code. The function sh RETURN the string converted to a list of digit characters following the procedure described above, but seems to not work correctly. Fix it. Example input, output, and non-functional code are provided below. def canada_to_us (can_zip): Convert a Canadian zip code to all digits. >>> canada_to_us ("V1X 3N5") ['1', '3', '5', '0','0'] >>> canada_to_us ("HOH OHO") '','0','' ,'',''] 111111 for i in range (len (can_zip)-1, -1, -1): if not can_zip [i].isdecimal(): del can_zip[i] can_zip.extend(['0']* (5-len (can_zip))) return can_zip

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!