Answer:
Follows are the code to this question:
n=input("Enter the first 12 digits of an ISBN-13 as a string:")#defining a varaible isbn for input value
if len(n)!=12: #use if block to check input value is equal to 12 digits
print("incorrect input") #print error message
elif n.isdigit()==False: #use else if that check input is equal to digit
print("incorrect input") #print error message
else:# defining else block
s=0 #defining integer vaiable s to 0
for i in range(12):#defining for loop to calculate sum of digit
if i%2==0: #defining if block to check even value
s=s+int(n[i])#add even numbers in s vaiable
else: #use else block for odd numbers
s=s+int(n[i])*3 #multiply the digit with 3 and add into s vaiable
s=s%10#calculate the remainder value
s=10-s#subtract the remainder value with 10 and hold its value
if s==10: #use if to check s variable value equal to 10
s=0#use s variable to assign the value 0
n=n+s.__str__() #u
Output:
please find attached file.
Step-by-step explanation:In the above Python code, the "n" variable is used for input the number into the string format uses multiple conditional statements for a check input value, which can be defined as follows:
- In if block, it checks the length isn't equal to 12, if the condition true, it will print an error message.
- In the else, if the block it checks input value does not digit, if the condition is true, it will print an error message.
- In the else block, it uses the for loop, in which it calculates the even and odd number sum, and in the odd number, we multiply by 3 then add into s variable.
- In this, the s variable is used to calculate its remainder and subtract from the value and use the if block to check, its value is not equal to 10 if it's true, it adds 0 into the last of n variable, otherwise, it adds its calculated value.