Question
#PYTHON You are the programmer for American Bank that defines a Personal Identification Number (PIN) as be a 6-digit numeric String. Security is a priority
#PYTHON
You are the programmer for American Bank that defines a Personal Identification Number (PIN) as be a 6-digit numeric String. Security is a priority for the Bank and they want to be able to evaluate these PINs using their weight, which is the sum of the absolute differences between each digit: For example, the weight of the PIN 236578 is 8 calculated as follows:
abs(2 - 3)-> 1
abs(3 - 6) -> 3
abs(6 - 5) -> 1
abs(5 - 7) -> 2
abs(7 - 8)-> 1
============> Weight: 1 + 3 + 1 + 2 + 1 = 8 The bank also needs to determine the weight of a series of PINs, by determining the sum of the absolute difference between the weights of each PIN. For example, if there are three (3) PINs in the series, the weight calculation follows: # PIN Weight Difference
1 837265 19
2 298374 20 1
3 928371 28 8 PIN Series Weight: 1 + 8 = 9
First, write a weight() function. This function accepts a String as an argument and calculates its weight. It must be named weight(), must accept a single String argument, use a for loop to calculate the weight and return a single Integer value
Then, Write a Python function main() that accepts no arguments and returns no values. The main() function should prompt the user to input the number of PINS to be evaluated, then using a for loop and the weight() function, it should calculate the weight of each value entered as well as the overall weight of the series
Output Example:
This program calculates the weight of a series of PINs
========================================
Enter the number of PINs to evaluate:3
Enter the first PIN: 837265
Enter the next PIN: 298374
Enter the next PIN: 928371
PIN series weight: 9
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