Created
April 13, 2020 21:39
-
-
Save gaycookie/bc97c4d3d90d6918c05da6a321309300 to your computer and use it in GitHub Desktop.
String comparing!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from re import sub | |
| class Main: | |
| def __init__(self): | |
| self.input = '' | |
| self.expected = [] | |
| self.percentage = 75 | |
| self.points = 0 | |
| def compare(self, context='', expected=[], percentage=75): | |
| self.input = context | |
| self.expected = expected | |
| self.percentage = percentage | |
| self.points = 0 | |
| if len(self.input) == 0: | |
| return False | |
| if len(self.expected) == 0: | |
| print("Needs to have at least one word in the List") | |
| return False | |
| ListInput = list(sub('[^A-Za-z0-9 ]+', '', self.input).split(" ")) | |
| ListExpected = self.expected | |
| for Word in ListInput: | |
| if Word.lower() in ListExpected: | |
| self.points += 1 | |
| print(int(100 * float(self.points) / float(len(ListExpected)))) | |
| if int(100 * float(self.points) / float(len(ListExpected))) >= self.percentage: | |
| return True | |
| return False | |
| print(Main().compare(context="I would like to host a minecraft server", expected=["minecraft", "make", "host", "server"], percentage=65)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment