TORONTO KIDS COMPUTER CLUB | Tuesday 17:30 Python Homework 21.05.11.
19439
post-template-default,single,single-post,postid-19439,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

Tuesday 17:30 Python Homework 21.05.11.

16 May Tuesday 17:30 Python Homework 21.05.11.

Question:
The International Standard Book Number (ISBN) is a 13-digit code for identifying books. These numbers have a special property for detecting whether the number was written correctly.

The 1-3-sum of a 13-digit number is calculated by multiplying the digits alternately by 1’s and 3’s (see example) and then adding the results. For example, to compute the 1-3-sum of the number 9780921418948 we add

9 ∗ 1 + 7 ∗ 3 + 8 ∗ 1 + 0 ∗ 3 + 9 ∗ 1 + 2 ∗ 3 + 1 ∗ 1 + 4 ∗ 3 + 1 ∗ 1 + 8 ∗ 3 + 9 ∗ 1 + 4 ∗ 3 + 8 ∗ 1

to get 120.

The special property of an ISBN number is that its 1-3-sum is always a multiple of 10.

Write a program to compute the 1-3-sum of a 13-digit number. Your program should input a 13-digit number and then print its 1-3-sum. Use a format similar to the samples below.

Sample Interactive Session 1
9780921418948

Output for Sample Interactive Session 1
The 1-3-sum is 120

Sample Interactive Session 2
9780921418052

Output for Sample Interactive Session 2
The 1-3-sum is 108

Hint:
1. You could use input() to ask user enter 13-digit number. 
   However, remember the information you entered will be a string if you only use input()

2. if you use variable name called digits to assign with input information,
   then you should use for loop like below to get every character from digits.
   for c in digits:

3. You should always use int() to convert every single character into integer number
No Comments

Sorry, the comment form is closed at this time.