Homework 3
assigned assigned THURS FEB 21 due THUR FEB 28 at 11:59 pm

Write a function called plot(s) in which s is a string representing a social security number written as contiguous digits (for instance, 509435456). It then prints each digit on a separate line followed by a colon and the digit printed the number of times equal to its value. Thus the output for 509435456 would be


You must do this two ways: the first way using a nested loop; the second way without a nested loop. Thus there will be two submissions each worth a maximum of 2 points. Note that a for loop, for instance, beginning with for j in range(0) is executed zero times.

Your string should be read in the main() method and transferred to the dummy parameter s in plot(s).

The input must be a nine-character string and contain no non-digits. If the input is not valid in the non-nested loop version, your program should be robust and prompt the user again to input data until the input is valid. Use a while for this. The form of the while should be

invalid = True
while invalid:
When valid data is read, the variable invalid should be set to False, otherwise the user should be told that his data was faulty and should retype the input. The nested loop version should not be robust.

Hint: Write the non-nested loop version in two stages, the first assumes valid data. Once this version works, test for data robustness. Submit the nested loop version and only the robust non-nested loop version.