Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Sage Cloud account and start a project called (Your Name) Coding Theory

ID: 3662144 • Letter: C

Question

Create a Sage Cloud account and start a project called (Your Name) Coding Theory Homework. Invite mc (swisherh@gmail.com) to collaborate with you on the project. Start a Sage Worksheet in your project and write in that worksheet either a function that calculates the ISBN-10 check digit given a list containing 9 digits as input, or a function that calculates the ISBN-13 check digit given a list containing 12 digits as input. If you are not familiar with python syntax, I highly recommend the Code academy course on python (https://www.codecademy.com/learn/python, it's really fun and helpful!

Explanation / Answer

Creating an account, project, and inviting and then creating worksheet can be done by you.

here I am giving the code for a

Function that calculates ISBN-10 check digit given a list containing 9 digits as input

PROGRAM:

ISBN=raw_input('Please enter the 9 digit number: ')

#ISBN=int(ISBN)

while len(ISBN)!= 9:

print('Please make sure you have entered a number which is exactly 9 characters long.')

ISBN=raw_input('Please enter the 9 digit number: ')

continue

else:

Sum=(int(ISBN[0])*10)+(int(ISBN[1])*9)+(int(ISBN[2])*8)+(int(ISBN[3])*7)+(int(ISBN[4])*6)+(int(ISBN[5])*5)+( int(ISBN[6])*4)+(int(ISBN[7])*3)+(int(ISBN[8])*2)

Mod=Sum%10

Digit10=10-Mod

if Digit10==10:

Digit10='X'

print('Your 10 digit ISBN Number is ' + str(ISBN)+str(Digit10))

Explaination:

Initially I am accepting an input from the user which is an integer of 9 digits exactly, if it contains more or less number of digits than 9 then I am prompting that the user should enter only 9 digits number and then storing the value in 'ISBN' variable

The input is accepted as a string, hence I am spliting the digits and converting them into integers and multiply each digit with suitable number and added the results as below and stored the result in 'Sum'

Sum=(int(ISBN[0])*10)+(int(ISBN[1])*9)+(int(ISBN[2])*8)+(int(ISBN[3])*7)+(int(ISBN[4])*6)+(int(ISBN[5])*5)+(int(ISBN[6])*4)+(int(ISBN[7])*3)+(int(ISBN[8])*2)

Then I am finding the remainder when Sum is divided with 10 and stored the result in 'Mod'

Mod=Sum%10

I calculated the 10 th digit as below

Digit10=10-Mod

if Digit10==10:

Digit10='X'

Next I concatenated the number input by the user and digit10 which gives the ISBN-10

print('Your 10 digit ISBN Number is ' + str(ISBN)+str(Digit10))

Hence the result.

Sample Output:

Please enter the 9 digit number: 4356
Please make sure you have entered a number which is exactly 9 characters long.

Please enter the 9 digit number: 345267189
Your 10 digit ISBN Number is 3452671893

Hope it is clear. Please give your valuable comments.