Skip to content

Commit ed6c538

Browse files
committed
Update var names and set button as disabled by default
1 parent 088a7ec commit ed6c538

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
def interest(*args, **kwargs):
22
# Signal that PyScript is alive by setting the ``Calculate``
33
# button away from disabled.
4-
ec = Element("calc") # noqa
4+
calculate_button = Element("calc") # noqa
5+
calculate_button.element.setAttribute("disabled")
56

67
# Now get the various inputs
7-
ep = Element("principal") # noqa
8-
er = Element("interest_rate") # noqa
9-
et = Element("time") # noqa
10-
p = float(ep.value)
11-
r = float(er.value)
12-
t = float(et.value)
8+
element_principal = Element("principal") # noqa
9+
element_rate = Element("interest_rate") # noqa
10+
element_time = Element("time") # noqa
11+
principal = float(element_principal.value)
12+
rate = float(element_rate.value)
13+
time = float(element_time.value)
1314
output1 = Element("simple_interest") # noqa
1415
output2 = Element("compound_interest") # noqa
15-
res1 = round(p + (p * r * t))
16-
res2 = round(p * ((1 + r) ** t))
16+
res1 = round(principal + (principal * rate * time))
17+
res2 = round(principal * ((1 + rate) ** time))
1718
output1.write("simple interest: " + str(res1))
1819
output2.write("compound interest: " + str(res2))
1920

2021

2122
def setup():
2223
"""When Pyodide starts up, enable the Calculate button."""
23-
ec = Element("calc") # noqa
24-
ec.element.removeAttribute("disabled")
24+
calculate_button = Element("calc") # noqa
25+
calculate_button.element.removeAttribute("disabled")

src/psc/gallery/examples/interest_calculator/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ img {
6363
border: 0;
6464
}
6565

66+
#form button:disabled, #form button[disabled] {
67+
background-color: #0097e863;
68+
}
69+
6670
header {
6771
height: 100px;
6872
}

0 commit comments

Comments
 (0)