Question: Write a Python script named assignment2.py that implements the following steps given an integer value: 1.) Double the value of every second digit beginning from

Write a Python script named assignment2.py that implements the following steps given an integer value:

1.) Double the value of every second digit beginning from the right. For example, the number 1386 has digits [1, 3, 8, 6] which become [2, 3, 16, 6].

2.) Add the digits of the doubled values and the digits that were not doubled from the original number. For example, [2, 3, 16, 6] becomes 2 + 3 + 1 + 6 + 6 = 18.

3. Calculate the remainder when the sum is divided by 10. For the previous example, the remainder is 8. If the result equals zero then return True otherwise return false.

You must define the following functions for this assignment:

toDigits takes an integer an returns a list of its digits

doubleEveryOther takes a list of digits and returns a new list of digits where every other number is doubled beginning from the right.

sumDigits takes a list of integers and sums up the digits of the numbers.

validate that indicates whether an integer is valid according to the algorithm described above. This function must use the functions defined previously in this list.

* Note it must be done using python 3 and not import any libraries, functions names must be in there so toDigits is one list doubleEveryOther another list

* Doesnt need to have an input needed, Can show how value 1386 can be turned into list and then made into another and later validated, as simple as needed nothing special

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 Databases Questions!