Python program called large_integer Include a function called input_large_number. The input must be numbers 0 - 9
Fantastic news! We've Found the answer you've been seeking!
Question:
Include a function called input_large_number. The input must be numbers 0 - 9 and must be appended to a list called digits
For example a number such as 123456789 is represented via a list as [1,2,3,4,5,6,7,8,9], where 9 is the least significant digit
Ensure that the function uses the try except clause and a loop to input multiple numbers to form the list.
During input, ensure that the most significant digit is not 0 (in other words the number does not have any leading zeros)
The digits are ordered from most significant to least significant in left-to-right order and each digits[i] is the ith digit of the integer
Return the list to main
Create another function called adding_one, that uses the list as the input parameter.
This function should contain the logic to add one to the least significant digit and the list contain the resulting number as represented by the list
The function should return the changed list
Note: The list should NOT be converted to a number to do the arithmetic. The processing must use the list as is
Create a function called main that calls the functions in the following order:
input_large_number. The function returns a list
Pass this list to the adding_one function that returns the changed list
Display the returned list
Note: each item in the list is a single digit.
For example:
input digits = [1, 2, 4, 5]
Adding one to the least significant item:
output: [1, 2, 4, 6]
input digits = [9, 9, 9]
Adding one to the least significant item:
output: [1, 0, 0, 0]
input digits = [8, 9]
Adding one to the least significant item:
output: [9, 0]
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date: