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
What does CPU stand for
nata0808 [166]

Answer:

Central Processing Unit

Explanation:

Principle part of any digital computer system

6 0
2 years ago
You want to make it possible for your smartphone to share its internet access wirelessly with your friends device which of the f
IrinaVladis [17]

Answer:WiFi or hotspots

Explanation:you will have to turn on your WiFi or hotspots on your smart phone and allow your friend to also turn his WiFi or hotspot after you will search for your WiFi and connect there he can use the internet

6 0
3 years ago
If your computer is frozen what is something you would do to troubleshoot the problem ​
SpyIntel [72]

Answer:

Ctrl+Alt+Del

Explanation:

It will take you to the task manager and you can highlight the program that is frozen, right click on it and select end task. Or hard reboot as a last resort.

4 0
1 year ago
Please help with this:
Tanzania [10]

Answer:

I'm not gonna give you the answer. I want you to think about this what is math, what is science, how does it help the world, and etc. These are some example questions to help.

Explanation:

5 0
3 years ago
What symbol precedes all structured references in formula autocomplete lists?
Zolol [24]
Structured references make it easier to use formulas with Excel tables by ... Use brackets around specifiers All table, column, and special item ...
4 0
2 years ago
Other questions:
  • To illustrate a point in a Word document with a simple chart, what commands should you select?
    8·2 answers
  • How can touch typing quickly but accurately improve your earnings (the money you can make)
    15·2 answers
  • Ciscon Telecom is a mobile operator in the European Union. The company provides personalized services to its customers, and its
    8·2 answers
  • How can officers in the armed services receive college educations? Select the best answer choice. A. All of the answers are corr
    11·1 answer
  • What will happen when you drag and drop a worksheet tab into another workbook WITHOUT holding the Ctrl key down?
    13·2 answers
  • The complete process for learning through repetition is to read, write, say, rest and revisit the information. Please select the
    12·2 answers
  • We will create a shopping cart, it is a dictionary mapping items in the car to the amount of that item. For example if there is
    9·1 answer
  • Computing devices translate digital to analog information in order to process the information
    12·1 answer
  • 7.2 code practice edhesive. I need help!!
    13·1 answer
  • Think of some local businesses that have websites. Look online and identify two different websites for businesses or services in
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!