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
alexandr1967 [171]
3 years ago
5

Assure that major, minor, sub1 and sub2 each contain four digit numbersIf less than four digits are entered in major OR minor OR

sub1 OR sub1, then the fieldshould be padding with zeroes at the beginning (e.g., if the user enters "33", then thescript should convert this to a four digit number "0033", if they enter "0", the scriptshould convert this to "0000")Blank fields are not allowed in the major, minor, sub1. sub2 or ta fieldsHowever, if an account number containing ALL zeroes is INVALID (i.e., if major=0000AND minor=0000 AND sub1=0000 AND sub2=0000, then the journal entry isconsidered INVALID because there will never be an Account Number composed of allzeroes)

Computers and Technology
1 answer:
Zigmanuir [339]3 years ago
4 0

Answer:

import re

#section 1

while True:

   try:

       major=input('Enter Major: ')

       if re.search(r'^\d{1,4}$',major):

           minor=input('Enter minor: ')

       else:

           raise

       try:

           if re.search(r'^\d{1,4}$',minor):

               sub1=input('Enter sub1: ')

           else:

               raise

       

           try:

               if re.search(r'^\d{1,4}$',sub1):

                   sub2=input('Enter sub2: ')

               else:

                   raise

           

               try:

                   if re.search(r'^\d{1,4}$',sub2):

                       break

                   else:

                       raise

               except:

                   print('enter a correct sub 2')

           except:

               print('enter a correct sub1')        

       except:

           print('Enter a correct minor ')            

   except:

        print('enter a correct Major')

#section 2

sub1= f"{int(sub1):04d}"

sub2= f"{int(sub2):04d}"

major= f"{int(major):04d}"

minor= f"{int(minor):04d}"

if major == '0000' and minor == '0000' and sub1=='0000' and sub2=='0000':

   print('INVALID!!! Acount Number')

else:

   print('-----------------------')

   print('Your Account Number is')

   print(major, minor, sub1, sub2)

   print('-----------------------')

Explanation:

The programming language used is python 3

The Regular  Expression Module was imported to allow us perform special operations on string variables.

This is the pattern that was used to check if an input was valid or invalid re.search(r'^\d{1,4}$',string)

what this pattern does is that it ensures that:

  1. (\d) represents digits that is any number from 0-9.
  2. ( ^ ) ensures that it starts with a digit.
  3. ({1,4}) accepts digits with length ranging from 1-4. i.e you can enter at least one digit and at most four digits.
  4. ($) ensures that the input ends with a digit
  5. string is the text that is passed to the pattern

we also made use of fstrings

sub1= f"{int(sub1):04d}"

the above line of code takes 'sub1' in this case, and converts it temporarily to an integer and ensures it has a length of 4 by adding 0's in front of it to convert it to a four digit number.

These are the major though areas, but i'll explain the sections too.

#section 1

In this section the WHILE loop is used in conjunction with the TRY and EXCEPT block and the IF statement to ensure that the correct input is given.

The while loop will keep looping until the correct input is inserted  before it breaks and each input is tested in the try and except block using the if statement and the regular expression pattern I explained, as a result, you cannot input a letter, a blank space, a punctuation or numbers with length greater than 4, it has to be numbers within the range of 1-4.

#section 2

The second section converts each entry to a four digit number and checks with an if statement if the entry is all zeros (0000 0000 0000 0000) and prints invalid.

Otherwise, it prints the account number.

check the attachment to see how the script runs.

You might be interested in
A system that receives drawing information from electronic cad files, prepares the printing materials, and controls the size and
nirvana33 [79]

Answer: A system that receives drawing information from electronic cad files, prepares the printing materials, and controls the size and resolution of reproductions is a(n) IMAGING system.

8 0
2 years ago
Krya needs help deciding which colors she should use on her web page. What can she use to help her decide.
Mars2501 [29]

Answer:

B. Color theory

Explanation:

A color theory can be defined as the science and art that guides people on how to use and combine various colors. Therefore, a good understanding of color theory would help someone to know the relationship (similarities and differences) between various type of colors such as primary colors, tertiary colors and secondary colors.

In this scenario, Krya needs help deciding which colors she should use on her web page. Thus, she should use color theory to help her decide on what color combinations are best for her web design.

6 0
2 years ago
​ If a class is reusable, that is to say that it can be used in several different applications, then it has been designed using
emmainna [20.7K]

High cohesion

fghfghdgfhgdhgh

6 0
3 years ago
Direct connections provide continuous access to the Internet. Many bandwidth options are associated with direct connections. Whi
Murljashka [212]

Answer:

Option B i.e, T1.

Explanation:

The T1 seems to be the licensed electronic transmission connection efficient for delivering the following bits each sec. T1 lines are required to transmit that server information of such an organization to both the Web or to link to such an ISP.

  • Option A is incorrect because their transmission is different as compared to the T1.
  • Option C is incorrect because consumers are equipped with a high rates broadband link from such a mobile wall socket over an installed telecommunications line.
  • Option D is incorrect because it seems to be a circuit-switched telecommunications line infrastructure that communicates both information as well as voice across a wire cable.
6 0
3 years ago
While you work on the customer's printer, he continues chatting about his network and problems he's been experiencing. One compl
Tanya [424]

Answer:

Most likely a serial cable. The type of cable is dependent on the WAN port, we can have serial or CAT 6 cable.

Explanation:

8 0
3 years ago
Other questions:
  • Explain why blocking ping (ICMP echo request) packets at an organization's edge router is not an effective defense against ping
    11·1 answer
  • 1. How does inertia affect a person who is not wearing a seatbelt during a collision? 
    14·2 answers
  • The contents of an array of type ______ can be displayed with the cout operator (without specifying an element). - 1 point(s)
    14·1 answer
  • Which of the following is a list of input devices?
    13·2 answers
  • Why should you need to have skills and an understanding about programming?
    8·1 answer
  • Communication is defined as__________.
    10·1 answer
  • Many companies use telephone numbers like 555-GET-Food so the number is easier for their customers to remember. On a standard te
    6·2 answers
  • Which of the examples is part of client-side code?
    12·1 answer
  • Answer any one: write a computer program:which you know.​
    6·1 answer
  • The action of entering data into your computer. This can be text typed in a word processing document, keywords entered in a sear
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!