|
1 | 1 | def interest(*args, **kwargs): |
2 | 2 | # Signal that PyScript is alive by setting the ``Calculate`` |
3 | 3 | # button away from disabled. |
4 | | - ec = Element("calc") # noqa |
| 4 | + calculate_button = Element("calc") # noqa |
| 5 | + calculate_button.element.setAttribute("disabled") |
5 | 6 |
|
6 | 7 | # 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) |
13 | 14 | output1 = Element("simple_interest") # noqa |
14 | 15 | 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)) |
17 | 18 | output1.write("simple interest: " + str(res1)) |
18 | 19 | output2.write("compound interest: " + str(res2)) |
19 | 20 |
|
20 | 21 |
|
21 | 22 | def setup(): |
22 | 23 | """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") |
0 commit comments