Apr-27-2017, 11:15 AM
So I need to return the value '-1' when s = any non-digits (other than spaces).
my code so far looks like :
Thankyou!!
Actually might as well post whole question to make it easier.
def parseVote(s):
parseVote(s) returns the vote from s. Return 0 for an empty vote, and -1 if there are any non-digits (other than spaces). For example,
parseVote("") = parseVote(" ") = 0,
parseVote("-3") = parseVote("no") = parseVote("1 5") = -1,
parseVote("15") = parseVote(" 15 ") = 15.
my code so far looks like :
def parseVote(s=None): if not s: print('0') elif s >= 0: print(s) else : print(-1)But its the middle 'elif' that needs changing to include letters.
Thankyou!!
Actually might as well post whole question to make it easier.
def parseVote(s):
parseVote(s) returns the vote from s. Return 0 for an empty vote, and -1 if there are any non-digits (other than spaces). For example,
parseVote("") = parseVote(" ") = 0,
parseVote("-3") = parseVote("no") = parseVote("1 5") = -1,
parseVote("15") = parseVote(" 15 ") = 15.