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
Juli2301 [7.4K]
3 years ago
11

Credit card numbers follow a standard system. For example, Visa, MasterCard, and Discpver Card all have 16 digits, and the first

digit serves to indicate the card brand. All Visa cards start with a 4; MasterCard cards always starts with a 5; and American Express cards start with a 2. Write a program that prompts for a 16-digit credit card and emits the name of the brand.Use the Try/Except/Else structure to ensure the user enters digits only. If the card brand cannot be determined or if the correct number of digits was not entered, the program should output "Unknown Card."
Computers and Technology
1 answer:
fgiga [73]3 years ago
5 0

Answer:

try:

   cardNumber = str(input('Enter your card number her: \n'))

   if (len(cardNumber) > 16 or len(cardNumber < 16)):

       raise

except:

   print ('You have entered an invalid cardNumber.')

else:

   if cardNumber.startswith("2"):

       print('American Express Card')

   elif cardNumber.startswith("4"):

       print('Visa Card')    

   elif cardNumber.startswith("5"):

       print('Master Card')    

   else:

       print('Unknown Card')

Explanation:

In the try block section:

The first line prompt the user for input, which is converted to string and assigned to cardNumber variable. The next line test the length of the cardNumber entered, if it is less than 16 or greater than 16; an exception is raise.

In the except section:

An error message is displayed telling the user that he/she has entered an invalid card number.

In the else section:

This is where is program check for type of card using an if...elif...else statement block. If the cardNumber start with 2; an output of "American Express card" is displayed. If the cardNumber start with 4; an output of "Visa card" is displayed. If the cardNumber start with 5; an output of "Master card" is display else "Unknown card" is displayed to the user.

You might be interested in
A(n application system is the master controller for all the activities that take place within a computer system. _______________
Elenna [48]
The answer is b.false
3 0
3 years ago
Does a 21.6v battery work with a 24 volt controller
Mila [183]
Yes but you will need more than one battery
3 0
3 years ago
Which type of operating system requires a keyboard in order to issue commands?
kicyunya [14]

Answer:

I said CLI.

Explanation:

''A command-line interface (CLI) processes commands to a computer program in the form of lines of text.''- Wikipedia

4 0
3 years ago
Which of the following do you need to remeber about true/false questions?
lina2011 [118]
All parts of a statement must be true for it to be true
7 0
3 years ago
What is the term of social media
seraphim [82]
It is used to describe a variety of web based platforms, applications, and technologies that allow people to socially interact online.
3 0
3 years ago
Other questions:
  • HURRYYY A friend of yours has E-mailed their English paper to you so that you can proofread it. Explain the tools you would use
    15·1 answer
  • what is happening when humans control the breeeding of living things to favor certain desired features
    9·1 answer
  • Why does a satellite requires two bridges?
    11·1 answer
  • People are able to predict future events to some extent because: (Select all that apply)
    11·1 answer
  • Would anyone know this
    10·2 answers
  • What will be the results of executing the following statements? x.setEditable(true); x.setText("Tiny Tim"); a. The text field x
    7·1 answer
  • A connection between files that allows data to be transferred from one file to another is a _______________________.
    6·1 answer
  • Why use LinkedIn automation for LinkedIn?
    10·1 answer
  • Examples of structures that can store homogeneous data element​
    14·1 answer
  • Explica el empleo de cuentas y contraseñas en archivos
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!