@deanang/

PyconEdu

Python

No description

fork
loading
Files
  • main.py
  • areaofcircle - Oka Kurniawan.py
  • areaofcircle1.py
  • areaofcircle2.py
  • areaofcircle3.py
  • scores.xlsx

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.3617941165629732","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"IzEgaW1wb3J0IGFzc2lnbm1lbnRzIGZvciBtYXJraW5nCmltcG9ydCBvcwptb2R1bGVzbmFtZSA9IFtdCmZvciBmIGluIG9zLmxpc3RkaXIoKToKICBmbmFtZSwgZmV4dCA9IG9zLnBhdGguc3BsaXRleHQoZikKICBpZiAiYXJlYW9mY2lyY2xlIiBpbiBmbmFtZToKICAgIG1vZHVsZXNuYW1lLmFwcGVuZChmbmFtZSkKbW9kdWxlcyA9IG1hcChfX2ltcG9ydF9fLCBtb2R1bGVzbmFtZSkKCiMyIENyZWF0ZSBNb2RlbCBzb2x1dGlvbgpmcm9tIG1hdGggaW1wb3J0IHBpCmRlZiBtb2RlbHNvbChyKToKICB0cnk6CiAgICBpZiByPDAgb3Igbm90IHR5cGUocikgaW4gKGludCwgZmxvYXQpOgogICAgICByYWlzZSBFeGNlcHRpb24KICBleGNlcHQ6CiAgICByZXR1cm4gKCJpbnZhbGlkIikKICBlbHNlOgogICAgcmV0dXJuIChwaSpyKnIpIAoKIzMgSGFuZGxlIGNyYXNoaW5nIG9mIGFzc2lnbm1lbnRzIGdyYWNlZnVsbHkKZGVmIGNyYXNoZ3JhY2VmdWxseShmKToKICBkZWYgaGVscGVyKHIpOgogICAgdHJ5OiBmKHIpCiAgICBleGNlcHQ6IHJldHVybiAiQ3Jhc2hlZCIKICAgIGVsc2U6IHJldHVybiBmKHIpCiAgcmV0dXJuIGhlbHBlcgoKIzQgTWFyayBhc3NpZ25tZW50cyBhZ2FpbnN0cyB0ZXN0IGNhc2VzCnRlc3RjYXNlcyA9IFszLCAzLjEsIDAsIC0zLCAtMy4xLCAidHdvIiwgVHJ1ZSwgMSszal0KcmVzdWx0cyA9IFtdCmZvciBtIGluIG1vZHVsZXM6CiAgcHJpbnQobS5uYW1lLCBtLmluZGV4KQogIHNjb3JlcywgdG90YWwgPSBbXSwgMAogIGZvciB0ZXN0IGluIHRlc3RjYXNlczoKICAgIGYgPSBjcmFzaGdyYWNlZnVsbHkobS5hcmVhT2ZDaXJjbGUpCiAgICBpZiBmKHRlc3QpID09IG1vZGVsc29sKHRlc3QpOgogICAgICB0b3RhbCArPSAxCiAgICAgIHNjb3Jlcy5hcHBlbmQoMSkKICAgIGVsc2U6CiAgICAgIHNjb3Jlcy5hcHBlbmQoMCkKICByZXN1bHQgPSBbbS5uYW1lLCBtLmluZGV4XStbeCBmb3IgeCBpbiBzY29yZXNdK1t0b3RhbF0KICByZXN1bHRzLmFwcGVuZChyZXN1bHQpCiAgcHJpbnQoIlx0VG90YWwgc2NvcmUgPSB7fSIuZm9ybWF0KHRvdGFsKSkKICAgIAojNSBFeHBvcnQgc2NvcmVzIHRvIGV4Y2VsIHNwcmVhZHNoZWV0IAppbXBvcnQgb3BlbnB5eGwKd2IgPSBvcGVucHl4bC5Xb3JrYm9vaygpCnNoID0gd2IuYWN0aXZlCnJvd0hlYWRlciA9IFsiTmFtZSIsICJJbmRleCJdK1tzdHIoeCkgZm9yIHggaW4gdGVzdGNhc2VzXStbIlRvdGFsIFNjb3JlIl0Kc2guYXBwZW5kKHJvd0hlYWRlcikKZm9yIHJvdyBpbiByZXN1bHRzOgogIHNoLmFwcGVuZChyb3cpCndiLnNhdmUoInNjb3Jlcy54bHN4IikK"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#1 import assignments for marking
import os
modulesname = []
for f in os.listdir():
  fname, fext = os.path.splitext(f)
  if "areaofcircle" in fname:
    modulesname.append(fname)
modules = map(__import__, modulesname)

#2 Create Model solution
from math import pi
def modelsol(r):
  try:
    if r<0 or not type(r) in (int, float):
      raise Exception
  except:
    return ("invalid")
  else:
    return (pi*r*r) 

#3 Handle crashing of assignments gracefully
def crashgracefully(f):
  def helper(r):
    try: f(r)
    except: return "Crashed"
    else: return f(r)
  return helper

#4 Mark assignments againsts test cases
testcases = [3, 3.1, 0, -3, -3.1, "two", True, 1+3j]
results = []
for m in modules:
  print(m.name, m.index)
  scores, total = [], 0
  for test in testcases:
    f = crashgracefully(m.areaOfCircle)
    if f(test) == modelsol(test):
      total += 1
      scores.append(1)
    else:
      scores.append(0)
  result = [m.name, m.index]+[x for x in scores]+[total]
  results.append(result)
  print("\tTotal score = {}".format(total))
    
#5 Export scores to excel spreadsheet 
import openpyxl
wb = openpyxl.Workbook()
sh = wb.active
rowHeader = ["Name", "Index"]+[str(x) for x in testcases]+["Total Score"]
sh.append(rowHeader)
for row in results:
  sh.append(row)
wb.save("scores.xlsx")