At Westonci.ca, we connect you with the best answers from a community of experienced and knowledgeable individuals. Discover detailed answers to your questions from a wide network of experts on our comprehensive Q&A platform. Join our Q&A platform to connect with experts dedicated to providing accurate answers to your questions in various fields.

Write a program that computes an integer's checksum. To compute the checksum, break the integer into its constituent digits and, working from right to left, doubling every second digit. If the product results in a number with two digits, treat those two digits independently. Then, sum all the digits for the final checksum. For example, 1496 has a checksum of 21. We compute this by first breaking 1496 into constituents and doubling the ever second digit => 6, 18, 4, 2. Then, the individual digits are summed as 6 + (1 + 8) + 4 + 2 = 21.

Sagot :

Answer:

def checksum(num):

   total = 0

   count = 0

   while num > 0:

       digit = num % 10

       count += 1

       if count % 2 == 0:

           digit *= 2

           while digit > 0:

               total += digit % 10

               digit //= 10

       else:

           total += digit

       num //= 10

   return total

   

num = int(input("Enter an integer: "))

print("Checksum:", checksum(num))

if there’s anything to amend, please let me know. thank you!

Thank you for your visit. We are dedicated to helping you find the information you need, whenever you need it. Thanks for using our platform. We aim to provide accurate and up-to-date answers to all your queries. Come back soon. Westonci.ca is here to provide the answers you seek. Return often for more expert solutions.