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]
2 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]2 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
Semiconductor memory is used mainly for primary storage even with its high cost. In another hand, the magnetic tape is the cheap
vodomira [7]
<span>In general you want to use the cheapest storage medium who's speed is compatible with the function it needs to perform. For active storage that's handled while running programs, you need memory whose speed is closely matched to the processor speed. And that would be the rather expensive semiconductor memory which is close to ideal for the task. But semiconductor memory has the disadvantage of being expensive and it loses the values stored when power is lost. So slower, persistent storage is used such as SSD (Solid State Drives) and hard disks. That media is cheaper, but slower, but still fast enough to handle tasks such as loading programs and data into memory for execution, or storing data generated by programs to persistent storage. But as with all man made things, disasters happen. Computers break down, hard disks crash, floods and fires happen, etc., and as a result data is lost. So we make backups. Backups have to have a lot of storage and they have to be cheap. But they don't need rapid access, you can start at the beginning and read (or write) all the way to the end. And for that purpose, magnetic tape is ideal. Magnetic tape is actually quite fast when you're simply streaming a continuous stream of data without any need to randomly access any piece of that data. And it's cheap, so you're willing to make a back up copy of your system and store that backup off site so a single disaster won't destroy both the primary system and the backup.</span>
3 0
3 years ago
The Freeze Panes feature would be most helpful for which situation?
sergiy2304 [10]

Answer:

i think a but not so sure

Explanation:

6 0
2 years ago
Technician A says that automotive engine blocks are usually classified by the number of cylinders the block. Technician B says t
viva [34]
<span>A. Both Technicians A and B is the answer</span>
8 0
3 years ago
When you are ready to print your document, what tab and command should you choose from the menu?
Margaret [11]

Answer:

File, Print UWU

Explanation:

3 0
3 years ago
Read 2 more answers
Sam has created a fashion website. There are many subscribers to his website. He has added new blogs, pictures, and articles abo
marusya05 [52]

Answer:

Post advertisements on social media and message the subscribers.

Explanation:

There is no point in not promoting and putting forward the work that he has been doing. All of the given options are about promoting the content but Sam needs to choose the ones which are efficient and seem professional as well.

Posting advertisements about the website promotes the content on a wider base and helps in luring more and more people to the website.

Messaging or sending an email to the subscribers is a healthy of letting the subscribers about the updates and latest posts.

8 0
3 years ago
Other questions:
  • Elise has just edited two photos of her cat and three different photos of her dog. She needs to save all five of these photos in
    5·2 answers
  • The syntax used for referencing cells with their worksheet names is the sheet name, followed by ____, then the usual column lett
    8·1 answer
  • The sequence of folders to a file or folder is called a(n) ________
    8·1 answer
  • Why is population composition by age important give reason​
    13·1 answer
  • What is the main difference between a search engine and a web browser?
    6·2 answers
  • _________________________ are the countable products resulting from a program, while ________________________ are the changes in
    9·1 answer
  • Write pseudocode for the question below:
    15·1 answer
  • Que es el sistema persona producto?​
    8·1 answer
  • Differences between dot_mattix printer and a line printer
    12·1 answer
  • Heyyyyyy who likes anime​
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!