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
____ is a linux-based operating system developed by the open handset alliance.
Misha Larkins [42]
The answer is Android
6 0
3 years ago
What landforms are likely to form at this boundary
Paha777 [63]
<span>Landforms that could be created at convergent boundaries would consist of: volcanoes, mountains, trenches, volcanic islands, and even deserts could result from effects of converging boundaries. The landforms are mountains.</span>
3 0
3 years ago
Problem 1 Calculating the tip when you go to a restaurant is not difficult, but your restaurant wants to suggest a tip according
DIA [1.3K]

Answer:

bill = float(input("Enter the bill amount: "))

rating = int(input("Choose a rating: 1 = Totally satisfied, 2 = Satisfied, 3 = Dissatisfied.: "))

if rating is 1:

   tip = bill * 0.2

elif rating is 2:

   tip = bill * 0.15

elif rating is 3:

   tip = bill * 0.1

print("The rating is: " + str(rating))

print("The tip is: $%.2f" % (tip))

Explanation:

*The code is in Python

- Ask the user for the <em>bill</em> and <em>rating</em>

- Depending on the <em>rating</em>, calculate the <em>tip</em> using <u>if else</u> statement i.e. If the rating is chosen as 1, calculate the tip by taking 20 percent of the bill.

- Print the <em>rating</em> and the <em>tip</em>

4 0
2 years ago
6. Which hypothesis about the fate of the universe says that it will expand continuously as the galaxies drift far apart and all
zaharov [31]
A. The big bang theory
6 0
3 years ago
Write a SQL statement to display the WarehouseID, the sum of Quantity On Order, and the sum of QuantityOnHand, grouped by Wareho
mariarad [96]

Answer:

The corrected question is:

Write an SQL statement to display the WarehouseID, the sum of QuantityOnOrder and sum of QuantityOnHand, grouped by WarehouseID and QuantityOnOrder. Name the sum of QuantityOnOrder as TotalItemsOnOrder and the sum of QuantityOnHand as TotalItemsOnHand. Use only the INVENTORY table in your SQL statement.

Answer to this corrected question:

SELECT WarehouseID,

SUM(QuantityOnOrder) AS TotalItemsOnOrder,

SUM(QuantityOnHand) AS TotalItemsOnHand

FROM INVENTORY

GROUP BY WarehouseID, QuantityOnOrder;

According to the given question:

SELECT WarehouseID,

SUM(QuantityOnOrder) + SUM(QuantityOnHand) AS TotalItemsOnHand    

FROM INVENTORY

GROUP BY WarehouseID, QuantityOnOrder;

Explanation:

  • In the SQL statement SELECT statement is used to select the data from the table. Here the SELECT statement is used to select WarehouseID, Sum of the columns QuantityOnOrder and QuantityOnHand from INVENTORY table.
  • The sum of QuantityOnOrder and QuantityOnHand columns are given the name of TotalItemsonHand (In case of the corrected question the sum of column QuantityOnOrder is named as TotalItemsOnOrder and the column QuantityOnHand is named as TotalItemsOnHand ) using Alias AS. Alias is the temporary name given to the columns or table to make them  more readable.
  • GROUP BY statement is used to arrange or "group" same data and is often use with aggregate functions like SUM function here. So the grouping here is done based on two columns WarehouseID and QuantityOnOrder.
  • SUM function in this SQL statement is an aggregate function to calculate the sum of all value in the columns QuantityOnOrder and QuantityOnHand.
3 0
3 years ago
Other questions:
  • What new information, strategies, or techniques have you learned that will increase your technology skills? Explain why its impo
    7·1 answer
  • In a program called Nature's Notebook, citizen volunteers make and report observations about seasonal changes in plants and anim
    15·1 answer
  • Give two reasons why it is important to upgrade your browser when a new version becomes available.
    8·1 answer
  • Question 16 (2 points) Question 16 Unsaved
    11·1 answer
  • Which of the following is a popular open source intrusion detection system that runs on SmoothWall?? Synchronous Dynamic Random
    6·1 answer
  • What element is not a selection in the Interface preferences? UI Character Presets UI Font Size UI Language UI Scaling
    9·1 answer
  • What is the advantage of maintaining a list of keywords while creating a design blueprint?
    13·2 answers
  • In this section of your final project, you will write a basic script to create and back up files. You will create this script wi
    11·2 answers
  • 1-5 Safety measures in the use of kitchen tools and equipment.​
    9·1 answer
  • If Anime Characters were real , Who Would Your Anime Wife Would Be (Tell Who And Why)
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!