1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
satela [25.4K]
3 years ago
12

python (Business: check ISBN-10) An ISBN-10 (International Standard Book Number) consists of 10 digits: d1d2d3d4d5d6d7d8d9d10. T

he last digit, d10, is a checksum, which is calculated from the other nine digits using the following formula: (d1 * 1 d2 * 2 d3 * 3 d4 * 4 d5 * 5 d6 * 6 d7 * 7 d8 * 8 d9 * 9) % 11 If the checksum is 10, the last digit is denoted as X according to the ISBN-10 convention. Write a program that prompts the user to enter the first 9 digits and displays the 10-digit ISBN (including leading zeros). Sample Run 1 Enter the first 9 digits of an ISBN as a string: 3601267 Incorrect input. It must have exact 9 digits Sample Run 2 Enter the first 9 digits of an ISBN as a string: 013601267 The ISBN-10 number is 0136012671 Sample Run 3 Enter the first 9 digits of an ISBN as a string: 013031997 The ISBN-10 number is 013031997X
Computers and Technology
1 answer:
iogann1982 [59]3 years ago
5 0

Answer:

<em>The programming language is not stated;</em>

<em>However, I'll answer this question using C++ programming language</em>

<em>The program uses few comments; See explanation section for more detail</em>

<em>Also, the program assumes that all input will always be an integer</em>

#include<iostream>

#include<sstream>

#include<string>

using namespace std;

int main()

{

string input;

cout<<"Enter the first 9 digits of an ISBN as a string: ";

cin>>input;

//Check length

if(input.length() != 9)

{

 cout<<"Invalid input\nLength must be exact 9";

}

else

{

 int num = 0;

//Calculate sum of products

for(int i=0;i<9;i++)

{

 num += (input[i]-'0') * (i+1);    

}

//Determine checksum

if(num%11==10)

{

 input += "X";

 cout<<"The ISBN-10 number is "<<input;

}

else

{

 ostringstream ss;

 ss<<num%11;

 string dig = ss.str();

 cout<<"The ISBN-10 number is "<<input+dig;

}

}  

 return 0;

}

Explanation:

string input;  -> This line declares user input as string

cout<<"Enter the first 9 digits of an ISBN as a string: ";  -> This line prompts the user for input

cin>>input;  -> The user input is stored here

if(input.length() != 9)  { cout<<"Invalid input\nLength must be exact 9";  }  -> Here, the length of input string is checked; If it's not equal to then, a message will be displayed to the screen

If otherwise, the following code segment is executed

else  {

int num = 0; -> The sum of products  of individual digit is initialized to 0

The sum of products  of individual digit is calculated as follows

for(int i=0;i<9;i++)

{

num += (input[i]-'0') * (i+1);

}

The next lines of code checks if the remainder of the above calculations divided by 11 is 10;

If Yes, X is added as a suffix to the user input

Otherwise, the remainder number is added as a suffix to the user input

if(num%11==10)  {  input += "X";  cout<<"The ISBN-10 number is "<<input; }

else

{

ostringstream ss;

ss<<num%11;

string dig = ss.str();

cout<<"The ISBN-10 number is "<<input+dig;

}

}  

You might be interested in
When you _____ a workbook, you control the ability users have to make changes to the file?
ehidna [41]
<span>When you protect a workbook, you control the ability users have, to make changes to the file.  This is t</span><span>o prevent other users from making changes, functions like adding, moving, deleting, or hiding worksheets, and renaming worksheets, you can </span>protect<span> it </span><span>with a password. </span>
5 0
3 years ago
Are there strategies or better solution that you can suggest besides paying for bags, which could reduce plastic bag pollution
astraxan [27]
The most obvious one would be recycling, another one would be to use plastic bags to hold things in your house, instead of boxes.  I run a business, and my business requires me to ship a lot.  I often use plastic bags as packaging material.  Hope this helps!
8 0
3 years ago
How would I CAST this variable to a STRING?<br> teeth = 32
maria [59]

Answer:

By using the str() function.

teeth = 32

print(str(teeth))

Explanation:

The str() function returns the string version of the given object.

4 0
3 years ago
Explain why a sound background in auto electricity and electronics is absolutely necessary if you are to troubleshoot
Fynjy0 [20]

the electrical system important for starting up your vehicle, but it is also important for keeping your vehicle running as you drive it. In addition, it is the electrical system that is also responsible for the functioning of things such as your headlights, your radio, and your dashboard

4 0
2 years ago
What protein is found in hair and nails
Yuliya22 [10]

Keratin is found in both hair and nails.

Hope this helps!

4 0
3 years ago
Read 2 more answers
Other questions:
  • You want to plug a keyboard into the back of a computer. you know that you need to plug the keyboard cable into a ps/2 port. whi
    9·1 answer
  • Who would use a CLI? (Command Line Interface)
    9·1 answer
  • Can you combine a wireless and wired lan in the same home
    14·1 answer
  • Technician A says that it's a good idea to perform a test drive before attempting repairs. Technician B says that it's a good id
    9·2 answers
  • Three homework questions I can't figure out, please help?
    11·1 answer
  • Think about the ways new communication technologies can make certain tasks easier for
    13·1 answer
  • Which media vehicle uses the Dreamweaver software for its design? A(n) "blank" uses the Dreamweaver software for its design.
    8·1 answer
  • In Outlook 2016, the Tell Me function can be accessed by
    15·2 answers
  • CreatePolicies<br> I need help with this in java.
    8·1 answer
  • Which of the following should be clicked to open Backstage View?
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!