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
algol13
3 years ago
11

Write a regular expression pattern that matches strings representing trains. A single letter stands for each kind of car in a tr

ain: Engine, Caboose, Boxcar, Passenger car, and Dining car. There are four rules specifying how to form trains. 1. One or more Engines appear at the front; one Caboose at the end. 2. Boxcars always come in pairs: BB, BBBB, etc. 3. There cannot be more than four Passenger cars in a series. 4. One dining car must follow each series of passenger cars. These cars cannot appear anywhere other than these locations. Here are some legal and illegal exemplars. EC Legal: the smallest train EEEPPDBBPDBBBBC Legal : simple train showing all the cars EEBB Illegal: no caboose (everything else OK) EBBBC Illegal: three boxcars in a row EEPPPPPDBBC Illegal: more than four passenger cars in a row EEPPBBC Illegal: no dining car after passenger cars EEBBDC Illegal: dining car after box car Hint: my RE pattern was 16 characters.
Computers and Technology
1 answer:
MAVERICK [17]3 years ago
6 0

Answer:

See explaination

Explanation:

import re

def isValidTrain(train):

pattern = r'^E+(((P|PP|PPP|PPPP)D)*(BB)*)*C$'

if re.match(pattern, train):

return True

return False

def checkAndPrintTrain(train):

print("Train", train, "is valid:", isValidTrain(train))

checkAndPrintTrain("EC")

checkAndPrintTrain("EEEPPDBBPDBBBBC")

checkAndPrintTrain("EEBB")

checkAndPrintTrain("EBBBC")

checkAndPrintTrain("EEPPPPPPDBBC")

checkAndPrintTrain("EEPPBBC")

checkAndPrintTrain("EEBBDC")

Sample output

Train EC is valid: True

Train EEEPPDBBPDBBBBC is valid: True

Train EEBB is valid: False

Train EBBBC is valid: False

Train EEPPPPPPDBBC is valid: False

Train EEPPBBC is valid: False

Train EEBBDC is valid: False

You might be interested in
Given a string variable named sentence that has been initialized , write an expression whose value is the the very last characte
Blizzard [7]
Strings can usually be dealt with as arrays of characters.

sentence[ -1 ]

sentence.substring( sentence.size() -1 );
8 0
3 years ago
What are the Database used in RDBMS and DBMS<br>please answer immediately​
frosja888 [35]

Answer:

The best example for the DBMS is certainly the Microsoft Access. And various examples of RDBMS are MySQL, Sql Server, Amazon DynamoDB and so on. However, its essential to understand the difference between the RDBMS and the DBMS. The main difference between the two is certainly that in the RDBMS the application stores the data in tabular manner, and DBMS the data is stored as files. In the RDBMS the tables comes with identifier known as primary key, and the data values are being saved in the form of tables.

Explanation:

Please check the answer section.

4 0
2 years ago
A picture drawn in 3 d is called?​
Varvara68 [4.7K]

Answer:

autostereogram

Explanation:

that^

6 0
3 years ago
Read 2 more answers
In the Application, "The Effect of FDI on Rentals and Wages in Singapore," the annual growth rate in real rental rates for the 1
stellarik [79]

Answer:

Explanation:

Production function: In simple words, production function refers to the functional relationship between the quantity of a good produced (output) and factors of production (inputs).

Production function: In simple words, production function refers to the functional relationship between the quantity of a good produced (output) and factors of production (inputs).

FDI: A foreign direct investment is an investment in the form of a controlling ownership in a business in one country by an entity based in another country.

  • Singapore has encouraged foreign firms to establish subsidiaries within its borders, especially in the electronics industry.
  • Singapore has the fourth-largest amount of FDI in the world.
  • What has happened to the rental rate and the wage?
  • Find in the attachment a table which shows much of this.
  •    The annual growth rate in rental rates for the 1970-1990 period using the production function and marginal product was -5%.
6 0
3 years ago
Write an algorithm to find perimeter of circle<br>​
Anna11 [10]

Answer:

Here’s one!

Given [math]R[/math], the radius of the circle.

Let [math]N,D\leftarrow 0[/math]

Repeat until [math]D[/math] is large enough (about 1,000,000)

[math]x,y\leftarrow U[0,1][/math]

If [math]x^2 + y^2\le 1[/math] then [math]N\leftarrow N+1[/math]

[math]D\leftarrow D+1[/math]

[math]P\leftarrow\frac{8NR}{D}[/math]

Return [math]P[/math]

[math]U[0,1][/math] is a uniform random number in the range [math][0,1][/math].

Explanation:

6 0
2 years ago
Other questions:
  • What microsoft operating systems started the process of authenticating using password and username
    14·1 answer
  • You're the network administrator for a company that has just expanded from one floor to two floors of a large building, and the
    7·1 answer
  • The number of bits that can be transferred per second over a given transmission medium.
    6·1 answer
  • What did major networks do to combat audience erosion in the 1990s?
    15·1 answer
  • Who is the intended audience of a pseudocode document?
    14·1 answer
  • What is the name of the option in most presentation applications with which you can modify slide elements?
    7·2 answers
  • WHAT ARE SOME PROS AND CONS OF HYDROGEN FUELL CELLS
    11·1 answer
  • You are a librarian! Ask the user for the last names of the authors of the five books they are returning. Print a list of those
    15·1 answer
  • How do we find the time complexity for this algorithm?
    6·1 answer
  • A(n) Blank______ database management system allows users to create, read, update, and delete data in a relational database. Mult
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!