Solution validation
- The aim of this challenge is to write code that can analyze code submissions.
- We'll simplify things a lot to not make this too hard.
- Write a function named validate that takes code represented as a string as its only parameter.
Your function should check a few things:
the code must contain the def keyword otherwise returnmissing defthe code must contain the : symbol otherwise return
missing :the code must contain ( and ) for the parameter list otherwise return
missing parenthe code must not contain () otherwise return
missing paramthe code must contain four spaces for indentation otherwise return
missing indentthe code must contain validate otherwise return
wrong namethe code must contain a return statement otherwise return
missing returnif all these conditions are satisfied, your code should return True.
Here comes the twist: your solution must return True when validating itself.
Test your solution here
My Solution
def validate(code):
if "def" not in code:
return "missing def"
if ":" not in code:
return "missing :"
if "(" not in code or ")" not in code:
return "missing paren"
if "(" + ")" in code:
return "missing param"
if " " not in code:
return "missing indent"
if "validate" not in code:
return "wrong name"
if "return" not in code:
return "missing return"
return True
All The best.
Top comments (0)