Question

IN PYTHON ''' Helper func 3: checksum_ISBN Input: a list with 9 single digit number in...

IN PYTHON

'''
Helper func 3: checksum_ISBN
Input: a list with 9 single digit number in it (first 9 digit in ISBN)
Output: print out: "The correct checksum digit is:__. Now we have a legit ISBN: _____"
Hint: just loop through 0-9, test every one with helper func1 to find out the one checksum that forms a legit ISBN
with the correct ISBN in lis (10 numbers), call helper func2 to format it correctly. Then print the final result.
'''
#def checksum_ISBN(partISBN):

------------------------------------------------------------------------------------------------------------------------------------------------

function1:

def check_legit_ISBN(ISBNLis):
size = len(ISBNLis)
total = 0
for ch in ISBNLis:
value = int(ch)
total += value * size
size -= 1
if total % 11 == 0:
return "Legit"
else:
return "Not Legit"
------------------------------------------------------------

function 2:

def format_ISBN(ISBNLis):
i=0

res="ISBN "

#appending the digits from the list

while(i<9):

res=res+str(ISBNLis[i])

i=i+1

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def check_legit_ISBN(ISBNLis):
    size = len(ISBNLis)
    total = 0
    for ch in ISBNLis:
        value = int(ch)
        total += value * size
        size -= 1
    if total % 11 == 0:
        return "Legit"
    else:
        return "Not Legit"

def format_ISBN(ISBNLis):
    i=0
    res="ISBN "
    #appending the digits from the list
    while(i<9):
        res=res+str(ISBNLis[i])
    i=i+1

def checksum_ISBN(partISBN):
    for num in range(0, 10):
        if check_legit_ISBN(partISBN + [num]) == "Legit":
            print("The correct checksum digit is:%d. Now we have a legit ISBN: %s" % (num, format_ISBN(partISBN + [num])))
            return


Please upvote, as i have given the exact answer as asked in question. Still in case of any concerns in code, let me know in comments. Thanks!

Add a comment
Know the answer?
Add Answer to:
IN PYTHON ''' Helper func 3: checksum_ISBN Input: a list with 9 single digit number in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • need help on all parts please and thank you (e) What is the correct output of...

    need help on all parts please and thank you (e) What is the correct output of this code? (2 pts) >>> def func(x): >>> res = 0 >>> for i in range (len (x)): res i >>> return res >>> print (func(4)) ( 4 5 ) 6 ()7 ( What could be described as an immutable list? (2 pts) () a dimple ( ) a tuple ( ) a truffle () a dictionary (g) What is the result of the...

  • Page 3 of 7 (Python) For each substring in the input string t that matches the...

    Page 3 of 7 (Python) For each substring in the input string t that matches the regular expression r, the method call re. aub (r, o, t) substitutes the matching substring with the string a. Wwhat is the output? import re print (re.aub (r"l+\d+ " , "$, "be+345jk3726-45+9xyz")) a. "be$jk3726-455xyz" c. "bejkxyz" 9. b. "be$jks-$$xyz" d. $$$" A object a- A (2) 10. (Python) What is the output? # Source code file: A.py class A init (self, the x): self.x-...

  • convert the following code from python to java. def topkFrequent(nums, k): if not nums: return [...

    convert the following code from python to java. def topkFrequent(nums, k): if not nums: return [ ] if len(nums) == 1: return nums [0] # first find freq freq dict d = {} for num in nums: if num in d: d[num] -= 1 # reverse the sign on the freq for the heap's sake else: d[num] = -1 h = [] from heapq import heappush, heappop for key in di heappush(h, (d[key], key)) res = [] count = 0...

  • Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX =...

    Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX = 100 #gets an integer def getValidInt(MINN, MAXX):     message = "Enter an integer between" + str(MINN) + "and" + str(MAXX)+ "(inclusive): "#message to ask the user     num = int(input(message))     while num < MINN or num > MAXX:         print("Invalid choice!")         num = int(input(message))     #return result     return num #counts dupes def twoInARow(numbers):     ans = "No duplicates next to each...

  • I'm making a To-Do list in Python 2 and had the program running before remembering that...

    I'm making a To-Do list in Python 2 and had the program running before remembering that my professor wants me to put everything in procedures. I can't seem to get it to work the way I have it now and I can't figure it out. I commented out the lines that was originally in the working program and added procedures to the top. I've attached a screenshot of the error & pasted the code below. 1 todo_list = [] 2...

  • I need this python program to access an excel file, books inventory file. The file called...

    I need this python program to access an excel file, books inventory file. The file called (bkstr_inv.xlsx), and I need to add another option [search books], option to allow a customer to search the books inventory, please. CODE ''' Shows the menu with options and gets the user selection. ''' def GetOptionFromUser(): print("******************BookStore**************************") print("1. Add Books") print("2. View Books") print("3. Add To Cart") print("4. View Receipt") print("5. Buy Books") print("6. Clear Cart") print("7. Exit") print("*****************************************************") option = int(input("Select your option:...

  • Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in...

    Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in PYTHON, new student. Please, please, I'm begging, Kindly answers all the questions. I'm hoping to grant my request. Thanks in advanced. 1.) What is the output of the following snippet? l1 = [1,2] for v in range(2): l1.insert(-1,l1[v]) print(l1)        a.) [1, 2, 2, 2]        b.) [1, 1, 1, 2]        c.) [1, 2, 1, 2]        d.) [1,...

  • Hi, can someone offer input on how to address these 4 remain parts the zybook python...

    Hi, can someone offer input on how to address these 4 remain parts the zybook python questions?   4: Tests that get_num_items_in_cart() returns 6 (ShoppingCart) Your output ADD ITEM TO CART Enter the item name: Traceback (most recent call last): File "zyLabsUnitTestRunner.py", line 10, in <module> passed = test_passed(test_passed_output_file) File "/home/runner/local/submission/unit_test_student_code/zyLabsUnitTest.py", line 8, in test_passed cart.add_item(item1) File "/home/runner/local/submission/unit_test_student_code/main.py", line 30, in add_item item_name = str(input('Enter the item name:\n')) EOFError: EOF when reading a line 5: Test that get_cost_of_cart() returns 10 (ShoppingCart)...

  • Python Problem Hello i am trying to finish this code it does not save guesses or...

    Python Problem Hello i am trying to finish this code it does not save guesses or count wrong guesses. When printing hman it needs to only show _ and letters together. For example if the word is amazing and guess=a it must print a_a_ _ _ _ not a_ _ _ _ and _a_ _ _ separately or with spaces. The guess has a maximum of 8 wrong guesses so for every wrong guess the game must count it if...

  • Undecimal to decimal&decimal to undecimal #Your code here Thank you! Binary-to-Decimal In a previous lab, we...

    Undecimal to decimal&decimal to undecimal #Your code here Thank you! Binary-to-Decimal In a previous lab, we considered converting a byte string to decimal. What about converting a binary string of arbitrary length to decimal? Given a binary string of an arbitrarily length k, bk-1....bi .box the decimal number can be computed by the formula 20 .bo +21.b, + ... + 2k-1. bx-1- In mathematics, we use the summation notation to write the above formula: k- 2.b; i=0) In a program,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT