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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started