Please help with this Python 3.4 Problem Write a function enrolments() that take
ID: 3814947 • Letter: P
Question
Please help with this Python 3.4 Problem
Write a function enrolments() 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.Explanation / Answer
Answer:
def
get_valid_string_count(courses):
num = 0 for str in courses:
isvalid = True
splitted = str.split(" ")
if(len(splitted) > 1):
str1 = splitted[0]
str2 = splitted[1]
if(len(str1) == 3):
for c in str1:
if(c.isalpha() == False):
isvalid = False
for c in str2:
if(c.isalpha() == True):
isvalid = False
else:
isvalid = False
else:
isvalid = False
if(isvalid):
num = num + 1
return num