Question: I am beginning to learn how to code and I am stuck on how to write the function below. I cannot use any types of
I am beginning to learn how to code and I am stuck on how to write the function below. I cannot use any types of loops since we have not learned about this yet. I can only use the built in types for strings that python has. My code for the case isnetid('wmw-2') returns true instead of false. I'm not sure how to fix this issue? I think my logic is off for the following lower_char = first_char and (second_char or third_char)? Any advice?
def isnetid(s): """ Returns True if s is a valid netid. network ids consist of 2 or 3 lower-case initials followed by a sequence of digits. Examples: isnetid('wmw2') returns True isnetid('2wmw') returns False isnetid('ww2345') returns True isnetid('w2345') returns False isnetid('WW345') returns False isnetid('wmw-2') returns False Parameter s: the string to check Precondition: s is a string """ lower = s.islower() print(lower) first_char = s[0].islower() second_char = s[1].islower() third_char = s[2].islower() lower_char = first_char and (second_char or third_char) print(lower_char) final = lower and lower_char return final
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
