Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: Using Python, The program must perform the following tasks: 1. Display a description of the programs purpose 2. Prompt the user for a 3-digit

Question: Using Python, The program must perform the following tasks: 1. Display a description of the programs purpose 2. Prompt the user for a 3-digit CVN 3. Calculate the sum of the absolute difference between each digit 4. Display the result

What I have:

def main(): # Display a description of the program's purpose print("This program determines the weight of an Integer") print("using the sum of the absolute difference between each digit.") # Prompt the user for a 3-digit CVN x=int(input("Please enter a 3-digit CVN: ")) # Call the weight() function providing the 3-digit # CVN as an argument weight(x) # The weight function requires and Integer parameter def weight(cvn): # Convert the Integer to a String num_str=str(cvn) # Initialize any necessary variables sum=0 y=0 # Setup a for loop that uses the digits as a sequence for i in num_str: # Sum the differences between each digit sum=sum+abs(y-int(i)) y=int(i) # Print the calculated weight of the integer print("The calculated weight of the integer is ", sum) # Call the main() function main()

Issue: math is incorrect

for example, when i enter 783 I get 3 for the weight and not 13

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions

Question

=+What is the most that you should pay to complete development?

Answered: 1 week ago

Question

=+development and make the product, should you go ahead and do so?

Answered: 1 week ago