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
________ employees state-of-the-art computer software and hardware to help people work better together.
natulia [17]

The correct answer is collaborative computing

Using state-of-the-art computer software and hardware to help people work better together is known as collaborative computing. Goal setting and feedback will be conducted via Web-based software programs such as eWorkbench, which enables managers to create and track employee goals.

6 0
3 years ago
_______ an embedded Word table to activate the Word features.
Bess [88]
The answer is C. double-click
3 0
3 years ago
Type the correct answer in the box. Spell all words correctly.
diamong [38]
The answer is handouts.
A handout is a pamphlet with information on your presentation you can give to your audience
8 0
3 years ago
A file named 'input.txt' contains a list of words. Write a program that reads the content of the file one word at a time. Check
Margarita [4]

Answer:

// here is code in java.

import java.io.*;

import java.util.Scanner;

class Main{  

    // function to check a word is palindrome or not

 private static boolean is_Palind(String str1)

 {

     // if length of String is 0 or 1

   if(str1.length() == 0 || str1.length() == 1)

   {

     return true;

   }

   else

   {

       // recursively check the word is palindrome or not

     if(str1.charAt(0) == str1.charAt(str1.length()-1))

     {

       return is_Palind(str1.substring(1,str1.length()-1));

     }

     

     else

     {

       return false;

     }

   }

 }

// driver function

 public static void main(String[] args)

 {// variable to store word

   String word;

   // BufferedWriter object

   BufferedWriter buff_w = null;

   // FileWriter object

   FileWriter file_w = null;

   // Scanner object

   Scanner sc = null;

   try

   {

       // read the input file name

     sc = new Scanner(new File("input.txt"));

     // output file

     file_w = new FileWriter("output.txt");

     // create a buffer in output file

     buff_w = new BufferedWriter(file_w);

     

     // read each word of input file

     while(sc.hasNext())

     {

       word = sc.next();

     // check word is palindrome or not

       if(is_Palind(word))

       {

           // if word is palindrome then write it in the output file

         buff_w.write(word);

         buff_w.write("\n");

       }

     }

     // close the buffer

     buff_w.close();

     // close the input file

     sc.close();

   }

   // if there is any file missing

   catch (FileNotFoundException e) {

     System.out.println("not able to read file:");

   }

   // catch other Exception

   catch (IOException e) {

     e.printStackTrace();

   }

 }

}

Explanation:

Create a scanner class object to read the word from "input.txt" file.Read a word  from input file and check if it is palindrome or not with the help of is_Palind() function.it will recursively check whether string is palindrome or not. If it is  palindrome then it will written in the output.txt file with the help of BufferedWriter  object. This will continue for all the word of input file.

Input.txt

hello world madam

level welcome

rotor redder

output.txt

madam

level

rotor

redder

3 0
2 years ago
"Players The files SomePlayers.txt initially contains the names of 30 football play- ers. Write a program that deletes those pla
kumpel [21]

Answer:

I am writing a Python program that deletes players from the file whose names whose names do not begin with a vowel which means their names begin with a consonant instead. Since the SomePlayers.txt is not provided so i am creating this file. You can simply use this program on your own file.

fileobj= open('SomePlayers.txt', 'r')  

player_names=[name.rstrip() for name in fileobj]  

fileobj.close()  

vowels = ('a', 'e', 'i', 'o', 'u','A','E','I','O','U')

player_names=[name for name in player_names  

                     if name[0] in vowels]

fileobj.close()

print(player_names)

Explanation:

I will explain the program line by line.

First SomePlayers.txt is opened in r mode which is read mode using open() method. fileobj is the name of the file object created to access or manipulate the SomePlayers.txt file. Next a for loop is used to move through each string in the text file and rstrip() method is used to remove white spaces from the text file and stores the names in player_names. Next the file is closed using close() method. Next vowels holds the list of characters which are vowels including both the upper and lower case vowels.

player_names=[name for name in player_names  

                     if name[0] in vowels]

This is the main line of the code. The for loop traverses through every name string in the text file SomePlayers.txt which was first stored in player_names when rstrip() method was used. Now the IF condition checks the first character of each name string. [0] is the index position of the first character of each players name. So the if condition checks if the first character of the name is a vowel or not. in keyword is used here to check if the vowel is included in the first character of every name in the file. This will separate all the names that begins with a vowel and stores in the list player_names. At the end the print statement print(player_names) displays all the names included in the player_names which begin with a vowel hence removing all those names do not begin with a vowel.

8 0
3 years ago
Other questions:
  • Fred opens a web browser and connects to the www.certskills.com website. Which of the following are typically true about what ha
    10·1 answer
  • Which of the following is NOT an ethical way of getting to the top of a web search?
    5·1 answer
  • Using the bitwise AND operation, the result of 1 AND 0 is ___________. 10100100 ___________ 11010101 = 01110001. A common way to
    15·1 answer
  • The ____ dialog box in windows vista appears each time a user attempts to perform an action that can be done only with administr
    12·1 answer
  • Word processing software, spreadsheet software, database software, and presentation software are examples of what category of co
    6·1 answer
  • How can you tell that you're driving in the right direction?
    14·1 answer
  • The flynn effect best illustrates that the process of intelligence testing requires up-to-date ________
    14·1 answer
  • How would you reduce or minimize the size of a "file"?
    5·1 answer
  • Complete the following sentence.
    7·1 answer
  • _________________ uses soap or detergent to physically remove germs, dirt, and impurities from surfaces or objects.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!