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
In this activity, you will submit the work you completed for the "Explore: Products" assignment. Type your response directly int
BabaBlast [244]

It should be noted that mate is the national beverage of countries such as Uruguay, Paraguay, and Argentina.

<h2>What is mate?</h2>

Mate tea is simply a beverage that is high in antioxidants and also contains caffeine.

It should be noted that mate is important as it raises morale, helps in sustaining the muscular system, and also allows an individual endure privations.

In conclusion, the drink is also usually taken by sportsmen.

Learn more about beverages on:

brainly.com/question/25884013

6 0
2 years ago
Calculate the data rate capacity for a 2400 baud signal where there are M=8 levels per symbol. a. 2400 bps b. 4800 bps c. 7200 b
zimovet [89]

Answer:

C. 7200 bps.

Explanation:

In networking, transmission lines or connectors and ports operates at a specific speed based on the port type and the cable or medium of transmission.

Baud rate is a concept in digital information technology that defines the rate of symbol per channel during transmission. The bit or data rate is the number of bits transfered in a link per second.

The relationship between baud rate and bit rate is;

Bit rate = baud rate x number of symbol bit level

To get the bit rate of a 2400 baud signal with symbol level = 8 = 2^3

Bit rate = 2400 x 3. = 7200 bps.

7 0
3 years ago
While designing a website, a(n) ____ allows you to identify the specific amount of space used on a particular page before it con
Aleks [24]
The answer would be A: wireframe, im pretty sure...

Hope this helped!! :)

8 0
3 years ago
Read 2 more answers
Frances is rearranging her furniture. (1) Also, she is moving the heavy oak bookcase to the back bedroom. (2) She has decided to
lozanna [386]

The first sentence that seems out of the logical order is the very first sentence, i.e, Also, she is moving the heavy oak bookcase to the bedroom.

A.  1

<u>Explanation:</u>

The fact that the sentence uses words like "she" and "also" leads to this conclusion. The logical order should move in a forward direction with the sentences forming a logical sequence.

The first sentence's structure is adding details to the actions which are already in progress and hence it should not be the first sentence. It should appear after the process of moving furniture has been started and further details are being added to it.

3 0
3 years ago
Read 2 more answers
Select the correct text in the passage.
grin007 [14]

Answer: Because it is known for that

Explanation:

I think it would be The Hawaiian islands are known for their volcanic activities

8 0
3 years ago
Other questions:
  • How do u get rid of this (the grey box)
    6·2 answers
  • _______________________ is a short-term program, typically 30 hours long, in which a therapist, social worker, or trained probat
    5·1 answer
  • An online service provider provides its users with hosted computers, an operating system, and a database management system (DBMS
    12·1 answer
  • Var faceS = 100; var mouthS = 30; ellipse(200, 200, faceS, faceS); ellipse(200, 220, mouthS, mouthS); How wide is the second ell
    12·1 answer
  • Which device makes computers that are connected to separate segments appear and behave as if they're on the same segment? (Pleas
    11·1 answer
  • Can change the tab colors of the worksheets in excel
    13·1 answer
  • ANSWER ASAP!!!!!
    10·2 answers
  • How many sets of number do both Hex and RGB values have?
    10·1 answer
  • Comment if u wanna text me on behance
    6·1 answer
  • Leon wants an output from his tablet. What should he look at?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!