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
11111 Power 2 sovle ​
erastovalidia [21]
123,454,321. you just multiply 11111 by itself
4 0
3 years ago
What statement best describes operating systems?
arlik [135]

Answer: D) Operating Systems manage the computer's random access memory (RAM)

Explanation:

It's not A because all modern computers use some form of an Operating System.

It's not B because some Operating Systems can cost hundreds of dollars.

While C has some truth to it, it's reversed. Operating Systems are there to manage and allocate system resources, and D is the better choice.

6 0
3 years ago
What are some of these new iPad extras? One is the iMarker. Crayola teamed up with another company to make it. It costs $29.99.
saul85 [17]
Another one is iMovie which allows you to edit and cut things.
5 0
3 years ago
If your network consists of all connected devices connecting to one central device, such as a switch, what type of topology is b
3241004551 [841]

Answer:

The correct answer to the given question is " Star Topology ".

Explanation

In the star topology, all the devices are connected to one central device in the network. It means every individual device is connected individually with the central device in the network.

The main drawback of star topology is that if the central device fails then all the device which are connected with them is also failed. The second drawback of star topology is to connect with the central device it requires more cabling.

8 0
3 years ago
Suppose the length of each packet is L bits. Also, assume the path from a server to a client includes N links each of rate R (i.
nignag [31]

Answer:

Attached is the solution

3 0
3 years ago
Other questions:
  • When a browser makes a request for a static web page, the web server a. finds the HTML for the page and renders it b. renders th
    11·1 answer
  • The acronym is used to define the process that allows multiple devices to share a single routable ip address.
    6·1 answer
  • When you send an echo request message with the ping program, a successful attempt will return a(n) ______ message.
    8·1 answer
  • Which address correctly represents one that is composed of two halves, one assigned to a network adapter manufacturer, and the o
    6·1 answer
  • The producer thread will alternate between sleeping for a random period of time and inserting a random integer into the buffer.
    7·1 answer
  • Why is it important to be a good digital citizen??
    11·1 answer
  • How should you handle possible suicides:
    10·1 answer
  • rray testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full cred
    5·1 answer
  • Subana is writing a program which will calculate the mean average of a set of numbers by adding the numbers and dividing the res
    11·2 answers
  • Apex
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!