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 is a paragraph on what i can write on what i learned from watching basic keyboard shortcuts using control functions video
finlep [7]

Answer:

Write the following nonsensical paragraph:

Explanation:

I learned how to navigate the computer efficiently. I learned how to use Ctrl + (key) to quickly do (something). ( Now reword that multiple times with different commands. ) Now I can harness my inner laziness to browse the computer at a faster speed.

6 0
4 years ago
The students of a college have to create their assignment reports using a word processing program. Some of the questions in thei
dusya [7]

Answer:

The insert table function of a word processing program will be the most useful for comparison.

Explanation:

Your welcome! :)

8 0
3 years ago
Jill edited James's document using Track Changes. James agrees with all of the edits and wants to incorporate them into his text
jenyasd209 [6]
The quick way for James to do so would be : A. open the tools menu, select options, and then select the track changes

with this method, James doesn't have to accept the edits one at a time which will waste his time

hope this helps
4 0
4 years ago
What does EDI stand for?
Georgia [21]
Electronic data interchange
4 0
3 years ago
Read 2 more answers
Which of the following indicates the main benefit of having a larger hard drive on a computer
dem82 [27]
I would say the primary Beni fit is more space for storage , but also it does effect the speed eventually. If your hard drive is almost full, everything will be slower
8 0
4 years ago
Other questions:
  • Ascending and descending are examples of
    5·2 answers
  • The type of business organization that can continue indefinitely is known as a
    11·1 answer
  • Using data from the BITS database, define a view named TopLevelClient. It consists of the number, name, address, balance, and cr
    9·1 answer
  • Jeremy is working with a team that is creating an application using attributes and associated methods. What type of programming
    8·1 answer
  • Choose the words that make the following sentence true.<br> Primary memory is
    5·1 answer
  • You must write a pseudocode process called swapSort which should sort a list of numbers using an algorithm called swap sort.
    13·1 answer
  • What intangible benefits might an organization obtain from the development of an
    5·2 answers
  • Read the steps in the process of making a video.
    5·2 answers
  • What is your favorite anime ( All movies and episodes related to them count )
    8·2 answers
  • What is the term for unsolicited Email​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!