Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE CODE IN PYTHON Write a function enrollments() that takes a list of string

ID: 3815149 • Letter: P

Question

PLEASE CODE IN PYTHON

Write a function enrollments() that takes a list of strings representing course IDs (e.g., “CSE 220”) and returns a count of how many strings define valid courses. Courses should be expressed as a three-letter subject in mixed uppercase/lowercase letters, followed by an optional space, followed by a three-digit number. So, ideally, each course is given in a form similar to "CSE 101" or "Phy 132". One obstacle to solving this problem is that sometimes extra characters – specifically, combinations of periods, dashes and commas – are inadvertently inserted in between letters. In such cases we still consider the course IDs to be valid.

Examples

Function Call : Return Value

enrollments([CSE 101’, ’AMS 310’, ’PHY 132’, ’Wrt 102’]) : 4

enrollments([’CSE114’, ’ECO330’, ’CHNN 101’, ’Ams 261’, ’MAT 200’, ’WRT101’, ’frn1012’, ’che 299’]) : 5

enrollments([’C-S-E 114’, ’C.S..E215’, ’AMS-211’, ’B,,,I.-O 255’, ’-ECO 102’]) : 3

Use regular expressions

Explanation / Answer

import re
def enrollments(courseLList):
   count=0
   for x in courseLList:
       if(re.match('wwwsddd$',x)!=None or re.match('wwwddd$',x)!=None):
           count=count+1
   print(count)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote