An ISBN (International Standard Book Number) is a 10 character string assigned to every commercial book before 2007. Each character is a digit between 0 and 9, but the last character might also be 'X'.
Write a program in isbn.py that asks the user for an ISBN and determines whether it is valid or not.
The check for validity goes as follows:
Multiply each of the first 9 digits by its position. The positions go from 1 to 9.
Add up the 9 resulting products.
Divide this sum by 11, and get the remainder, which is a number between 0 and 10.
If the remainder is 10, the last character should be the letter 'X'. Otherwise, the last character should be the remainder (a single digit).
```python
98765432321X
isbn = input('What is the ISBN? ')
first_nine_digits = isbn[:9]
total = 0
if len(isbn) > 10:
raise Exception("Too long")
for index, value in enumerate(first_nine_digits):
total = total + int(value) * (index +1)
remainder = total % 11
if remainder == 10:
if isbn[-1] == 'X':
return 'Valid'
else:
return 'Invalid'
else:
if isbn[-1] == remainder:
return 'Valid'
else:
return 'Invalid'
# Write a program in primes.py that asks the user for a number and then factorises the number into primes.
input_number = Input('Enter a number:')
prime_factors = []
current_prime = 2
if (input_number % current_prime == 0):
prime_factors.append(current_prime)
input_number /= current_prime
else
current_prime += 1
return prime_factors