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
Why do designers of smartphones hide computer processing details from
geniusboy [140]

Answer:

b.you can focus on otherthings

6 0
2 years ago
Read 2 more answers
Super Scores
Sindrei [870]

Answer:

Replace:

<em>//CODE HERE  </em>

<em>//output the max score for each section and compute & output total too.  </em>

with the following lines of codes:

<em>int num;  </em>

<em>for(int i=0; i<numtakes; i++) { </em>

<em>for(int j=0; j<numsections; j++) { </em>

<em>   cin>>num; </em>

<em>   if(num>maxScores[j]){ </em>

<em>       maxScores[j] = num;    } </em>

<em>}  } </em>

Explanation:

Your program is poorly formatted. (See attachment for correct presentation of question)

What's required of the us is to complete the source program.

The codes has been completed in the Answer section above, however, the line by line explanation is as follows:

<em />

<em>This line declares num that gets user for input for each entry</em>

<em>int num;  </em>

<em>This line iterates through the number of takes</em>

<em>for(int i=0; i<numtakes; i++) { </em>

<em>This line iterates through the number of sections</em>

<em>for(int j=0; j<numsections; j++) { </em>

<em>This gets user input for each entry</em>

<em>   cin>>num; </em>

<em>The following if condition determines the greatest entry in each section</em>

<em>   if(num>maxScores[j]){ </em>

<em>       maxScores[j] = num;    } </em>

<em>}  } </em>

<em>For further explanation, I've added the complete source file as an attachment where I used comments to explain each line.</em>

Download cpp
8 0
3 years ago
In which situation will file compression be required to complete the task
Kryger [21]
To make easy transfers and to limit the amount of files being moved at a time
4 0
3 years ago
Careers in information technology deal with
podryga [215]

Answer:

A

Explanation:

A would be the best possible answer

3 0
3 years ago
Read 2 more answers
Which program or security application prevents access between a private and trusted network, and other untrusted networks?
zavuch27 [327]

The answer is a firewall. A firewall is capable of blocking unwanted and/or unauthorized connections from accessing either your computer or your entire network thereby resulting in data loss and information theft.

7 0
3 years ago
Read 2 more answers
Other questions:
  • Bullets in a text box will do which of the following?
    9·2 answers
  • What is the problem with the code snippet below? public class Test { public static void main(String[] args) { System.out.println
    6·1 answer
  • When Creating a FPS game what basic rules would you add?
    12·1 answer
  • How many times will line 7 be executed when the following code is run?
    5·1 answer
  • Question 1 (3 points)
    6·2 answers
  • How do you describe Microsoft excel?
    13·1 answer
  • Define the terms network, LAN, WAN, and Internet.
    11·1 answer
  • What type of dns record holds the dnssec public signing key?
    9·1 answer
  • Consider that a man is watching a picture of a Black Horse. He receives an external stimulus from input channel. Man gains some
    14·1 answer
  • What are the different elements of a window?​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!