Answered You can hire a professional tutor to get the answer.

QUESTION

PART 1 Spongebob has a claim about the years 1988 to 2012 .He asserts that every year in that range, has repeated digits in the 4-digit year...

PART 1

Spongebob has a claim about the years 1988 to 2012. He asserts that every year in that range, has repeated digits in the 4-digit year identifier. 

For example, the year "1988" has two of the digit "8", when you consider the four individual digits in that year. The year "1987" has no repeated digits.

Does a range of years have repeating digits?

I should write python code to prove or disprove the jaundiced protozoan's conjecture. Achieving it by exhaustive enumeration of the individual cases. 

One Possible Algorithm to solve this problem:

1. start by setting up a range that counts in units from 1987 to 2012

2. Use the range to control a "for" loop that steps through each individual year.

 set up a list of ten elements, initialized to zero at the top of the loop over years.

   digitCount = [0,0,0,0,0,0,0,0,0,0]

or

   digitCount = [0] * 10

3. That list will keep track of the individual digits used for one year. Say the year is 1987.  That contains digits 1, 9, 8 and 7.

Loop over the digits in the year, 1, 9, 8, and 7. You could accomplish it easily by turning the int 1987 into a string, and iterating over the characters in the string.

year = str(1987)

for d in year:

  print ("one digit as string is", d)

  dn = int(d)

  print ("one digit as int is", dn)

You will indicate the presence of a specific digit by adding one to the corresponding item in the digitCount list. If the digit is 3, add one to digitCount[3].

After processing the first digit of "1987", the digitCount list will look like:

   [0,1,0,0,0,0,0,0,0,0]  # we added 1 to digitCount[1], to indicate that we have seen one 1.

After processing all 4 digits in the year 1, 9, 8, 7, the digitCount list will look like:

   [0,1,0,0,0,0,0,1,1,1]   

4. Here's the kicker: after processing all 4 digits in the year, any value > 1 in digitCount means that digit occurs more than once!

After processing 1, 9, 9, 1, , the digitCount list will look like:

   [0,2,0,0,0,0,0,0,0,2]   

In general, 

when the j'th item of digitCount = 0, it means that digit j is not in the year

when the j'th item of digitCount = 1, it means that digit j is in the year once

when the j'th item of digitCount = 2, it means that digit j is in the year twice

when the j'th item of digitCount = 3, it means that digit j is in the year three times, and so on.

Now you print the year, then simply iterate over all the elements of digitCount, printing out the item number of each item with a "greater than 1" count.  If digitCount[6] = 3, that means the digit "6" appears 3 times in the year. It would be a year like, say, 6066.  Format the output nicely. 

That deals with one year. Repeat in a loop that iterates over all years. 

PART 2

Please write python code to print a non-integral multiplication table.We don't have the features to draw grid lines, so just print the numbers, and make sure they are perfectly aligned in all directions.  

1. The table should not run from 1 to 10, but from 0.5 to 5.5, in 1.0 steps. I.e. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5. The first entry in the table (top left) will be 0.5 * 0.5 or 0.25.  The last entry in the table will be 5.5 * 5.5, or 30.25.

2. The table should be formatted to be as uniform and as neat as possible. 

3. Don't print any purely decorative elements, like vertical bars, semi-colons, hyphens etc.Make sure all the decimal points are aligned in the same columns.

3. Use symbolic constants to represent the number of rows and columns.Make sure the program still works perfectly if the row/cols are not the same number.Make sure the program still works perfectly if the row/cols are increased as far as 12 x 12 or reduced as far as 2 x 2

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question