Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

Students also viewed these Programming questions

Question

Hot Holidays Hot Holidays

Answered: 1 week ago

Question

LG4 Understand the different kinds of common stock values.

Answered: 1 week ago