Commit 1154a9101a1dd7c3f9bf78c653c7c052b9d01316
1 parent
f9bea841
Exists in
master
and in
1 other branch
minor changes in demo/solar_system/correct-first_3_planets.py
Showing
1 changed file
with
10 additions
and
9 deletions
Show diff stats
demo/solar_system/correct-first_3_planets.py
@@ -2,26 +2,27 @@ | @@ -2,26 +2,27 @@ | ||
2 | 2 | ||
3 | import re | 3 | import re |
4 | import sys | 4 | import sys |
5 | +import time | ||
5 | 6 | ||
6 | s = sys.stdin.read() | 7 | s = sys.stdin.read() |
7 | 8 | ||
8 | -# set of words converted to lowercase | ||
9 | -answer = set(re.findall(r'[\w]+', s.lower())) | ||
10 | -answer.difference_update({'e', 'a', 'planeta', 'planetas'}) # ignore these | 9 | +ans = set(re.findall(r'[\w]+', s.lower())) # convert answer to lowercase |
10 | +ans.difference_update({'e', 'a', 'o', 'planeta', 'planetas'}) # ignore words | ||
11 | 11 | ||
12 | # correct set of planets | 12 | # correct set of planets |
13 | planets = {'mercúrio', 'vénus', 'terra'} | 13 | planets = {'mercúrio', 'vénus', 'terra'} |
14 | 14 | ||
15 | -correct = set.intersection(answer, planets) # the ones I got right | ||
16 | -wrong = set.difference(answer, planets) # the ones I got wrong | 15 | +correct = set.intersection(ans, planets) # the ones I got right |
16 | +wrong = set.difference(ans, planets) # the ones I got wrong | ||
17 | 17 | ||
18 | grade = (len(correct) - len(wrong)) / len(planets) | 18 | grade = (len(correct) - len(wrong)) / len(planets) |
19 | 19 | ||
20 | +comments = 'Certo' if grade == 1.0 else 'as iniciais dos planetas são M, V e T' | ||
21 | + | ||
20 | out = f'''--- | 22 | out = f'''--- |
21 | -grade: {grade}''' | 23 | +grade: {grade} |
24 | +comments: {comments}''' | ||
22 | 25 | ||
23 | -if grade < 1.0: | ||
24 | - out += '\ncomments: Vou dar uma ajuda, as iniciais são M, V e T...' | 26 | +time.sleep(5) |
25 | 27 | ||
26 | print(out) | 28 | print(out) |
27 | -exit(0) |