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
5. A Disk defragmenter tool does what to a computer HDD?
Ivenika [448]

Answer:It rearranges the files on a hard drive to get quicker access to them.

5 0
2 years ago
What are the different types of topology?​ in details
wlad13 [49]

Answer:

<h2> <u>NETWORK</u> <u>TOPOLOGY</u> .</h2>

This tefers to how nodes are connected to the network.

Types of topology.

  • Physical topology.
  • Logical topology.

In physical topology,nodes are connected physically using wires(cables).

Types of physical topology include:

  • Bus topology
  • Tree topology
  • Hybrid topology
  • Star topology
  • Ring topology.

Hope it helps you,any question so far...comment !!!

3 0
1 year ago
Read 2 more answers
Is the app scener safe? its a chrome webstore app on computer.​
Sophie [7]

Answer:

Maybe

Explanation:

If you are unsure if a website is safe look for signs. If its asking you to allow advertisement then no. I suggest you download a VPN before going to the website just to be safe

5 0
3 years ago
How many basic elements of QBASIC are there
Masteriza [31]
<h2>6</h2>

The elements used in Qbasic:

  • Character set.
  • Variables.
  • Constants.
  • Operator and Operands.
  • Expression.
  • Statements.
6 0
3 years ago
True / Fasle
Liono4ka [1.6K]

Answer:

False

Explanation:

3 0
3 years ago
Other questions:
  • To keep information beyond reach of unauthorized users, is to keep the information _____. Group of answer choices simple verifia
    7·1 answer
  • Which markup language would be considered the most current for web design? HTLM, HTML5, XHTLM, XHTML 6
    14·2 answers
  • You can use automatic link-checking software to identify invalid hyperlinks. if you find invalid links, what should you do next?
    13·1 answer
  • What is one difference between a web page and a web application? Web pages provide information, while web applications allow the
    8·1 answer
  • which virtue you need to secure information by limiting computer access to authorized personnel only?
    10·1 answer
  • 1. Itemise the order in which BASIC executes arithmetic operation.
    13·1 answer
  • Microsoft’s SharePoint server product dramatically altered the content and records management (RM) markets. Crocker (2015), edit
    6·1 answer
  • Which two options are negotiated via ncp during the establishment of a ppp connection that will use the ipv4 network layer proto
    7·1 answer
  • Hewo everyone look at me I look ugly don't I<br>​
    6·2 answers
  • From which of the following locations can you run a single line of the program?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!