-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun
executable file
·79 lines (61 loc) · 2.13 KB
/
run
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/python3
from inginious import input, feedback, rst
# random input
km = 10*int(input.get_input("@random")[0] * 200 + 10) #km
bw = int(input.get_input("@random")[1] * 50 + 5) # Mbps
def isfloat(value):
try:
float(value)
return True
except:
return False
def almost(answer,value):
if((answer<=(value+value/20)) and (answer>=(value-value/20))):
return True
else:
return False
# length of data frame
dlen=1000
# length of control frame
clen=40
#propagation delay in msec
prop=km*5/1000
rtt=1000*(dlen/(bw*1000000)+0.0001+clen/(bw*1000000)+2*prop)
grade=0
answer1 = input.get_input("q1")
answer2 = input.get_input("q2")
if(isfloat(answer1)):
if (almost(float(answer1),prop)):
feedback.set_problem_result("success","q1")
feedback.set_problem_feedback("Correct","q1")
grade+=30
else:
feedback.set_problem_result("failed","q1")
response="Your answer is incorrect.\n"
if(almost(float(answer1),1000*prop)):
response+="Remember that propagation delay is in microseconds per kilometer while your answer must be in milliseconds.\n"
feedback.set_problem_feedback(response,"q1")
else:
feedback.set_problem_result("failed","q1")
feedback.set_problem_feedback("Your answer is not a number","q1")
if(isfloat(answer2)):
if (almost(float(answer2),rtt)):
feedback.set_problem_result("success","q2")
feedback.set_problem_feedback("Correct","q2")
grade+=70
else:
feedback.set_problem_result("failed","q2")
response="Your answer is incorrect.\n"
if(almost(float(answer2),1000*rtt)):
response+="Remember that the round-trip-time must be expressed in milliseconds.\n"
if(almost(float(answer2),rtt-2*prop)):
response+="Remember that the round-trip-time includes both the time to transmit the data and control frames and twice the propagation delay.\n"
feedback.set_problem_feedback(response,"q2")
else:
feedback.set_problem_result("failed","q2")
feedback.set_problem_feedback("Your answer is not a number.","q2")
feedback.set_grade(grade)
if(grade>50):
feedback.set_global_result("success")
else:
feedback.set_global_result("failed")