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
Consider the pseudo-cpu discussed in class. the instruction format is 16 bits, which is subdivided into 4-bit opcode field and 1
sp2606 [1]
I need a picture or an answer choice
6 0
4 years ago
Which of the following is a Microsoft solution
Sholpan [36]

Answer:

TS RemoteApp

Explanation:

The question is wrong. Correct question and choices are:

Which of the following is a Microsoft solution that runs on a Microsoft Terminal Services server but appears, to end users, as if it were actually running on their systems?

a.TS Web Access

b.DirectAccess

c.TS RemoteApp

d.Terminal Services for Applications

Terminal Services RemoteApp can be used remotely via remote desktop protocal (RDP) but look like to users as if they are running locally by successfully integrating user's desktop.

These applications are available since Windows Server 2008 and can be used on various windows operating systems.

7 0
4 years ago
All of the following are advantages of database-stored information, except: Question 3 options: 1) Reduced information redundanc
enot [183]

Answer:

3) Reduced information integrity.

Explanation:

This is not an advantage, Information integrity is a key factor when storing information on a database. As multiple users will access it, they will need this data to be authentic and dependable. Any reduction in information integrity is a great disadvantage.

5 0
3 years ago
I’ll mark brainlest
faust18 [17]

<u>Home </u><u>and</u><u> Insert</u>

In Microsoft office, to create a text box you will go to insert and then there will be various options there and you will see text box marking. so you will just have to click on text box and you can create it however you want to do it.

It's such a easy step(◕ᴗ◕✿)

3 0
3 years ago
Read 2 more answers
What indicates that one color is dominating a picture
Sonbull [250]
When the color is mostly on the pic, it means it is dominating the picture.
3 0
4 years ago
Other questions:
  • PLEASE HELP!!!!!!!!!!!
    7·1 answer
  • Which are examples of embedded systems? Choose two answers.
    15·1 answer
  • ​Case-Based Critical Thinking Questions​Case 9-1Melissa, a computer science engineering student, is learning the basics of progr
    11·1 answer
  • Why is technology potentially important to the banking industry? What consumer needs does it fulfill?
    15·1 answer
  •   Why does a shaded-pole motor run at a constant speed?  A. The lines of force do not change direction.  B. The current through
    15·1 answer
  • An investment website can tell what devices are used to access the site. The site managers wonder whether they should enhance th
    10·1 answer
  • A robot can complete 7 tasks in hour. Each task takes the same amount of time.
    15·2 answers
  • When I click on someone who asked a question and i want to see there answer it is always blurred and when I asked a question I c
    8·1 answer
  • Select the correct answer from each drop-down menu.
    10·1 answer
  • What is shotgun microphone?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!