-
Notifications
You must be signed in to change notification settings - Fork 14
Meg interest calculator #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0f986d3
The loading of the local file wasn't needed.
pauleveritt 7b10927
Pushing a flavor with a broken test, where the mock does self.documen…
pauleveritt 5a4bf0e
PyCharm -> PyScript
pauleveritt 14415f8
Small styling tweaks and contributing docs
FabioRosado 088a7ec
Update example name
FabioRosado ed6c538
Update var names and set button as disabled by default
FabioRosado f96b6fd
More tweaks to interest calculator
FabioRosado 43970ee
update precommit
FabioRosado 1c87074
Fix pre-commit issues
FabioRosado 84dc20c
Types
FabioRosado 0904f0f
Cleaned up the styling. Fixed an issue with a BOM that was messing up…
pauleveritt 8c548f4
Merge branch 'main' into meg-interest-calculator
pauleveritt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/psc/gallery/examples/interest_calculator/calculator.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
def interest(*args, **kwargs): | ||
# Signal that PyScript is alive by setting the ``Calculate`` | ||
# button away from disabled. | ||
ec = Element("calc") # noqa | ||
|
||
# Now get the various inputs | ||
ep = Element("principal") # noqa | ||
er = Element("interest_rate") # noqa | ||
et = Element("time") # noqa | ||
p = float(ep.value) | ||
r = float(er.value) | ||
t = float(et.value) | ||
output1 = Element("simple_interest") # noqa | ||
output2 = Element("compound_interest") # noqa | ||
res1 = round(p + (p * r * t)) | ||
res2 = round(p * ((1 + r) ** t)) | ||
output1.write("simple interest: " + str(res1)) | ||
output2.write("compound interest: " + str(res2)) | ||
|
||
|
||
def setup(): | ||
"""When Pyodide starts up, enable the Calculate button.""" | ||
ec = Element("calc") # noqa | ||
ec.element.removeAttribute("disabled") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | ||
|
||
<head> | ||
<meta charset="utf-8"/> | ||
<title>Interest Calculator</title> | ||
<link rel="stylesheet" href="styles.css"/> | ||
<script defer src="../../../pyscript/pyscript.js"></script> | ||
</head> | ||
|
||
<body> | ||
|
||
<header> | ||
<h1 id="header_h1">Welcome to the Compound Calculator!</h1> | ||
</header> | ||
|
||
<main style=""> | ||
FabioRosado marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<div class="flexelement" id="first_div"> | ||
<p id="first_p"> | ||
Welcome to the "Simple and Compound Interest Calculator!" | ||
<br/> | ||
<strong>"how does it work?"</strong> | ||
to use the "Simple and Compound Interest Calculator", please enter the input data into the form. | ||
after clicking "Calculate", your result will be shown at the bottom of the form. | ||
</p> | ||
|
||
<div style="margin-left: 15%;"> | ||
<div style="width: 100%;"> | ||
<input type="radio" name='expander' id="expander-1"> | ||
<label class="expander_label" for="expander-1">Compound Interest Formula »</label> | ||
<img src="compound-interest.png" alt="Compound Interest" | ||
style="height: 200px;"/> | ||
</div> | ||
|
||
<div style="margin-top: 25px;"> | ||
<input type="radio" name='expander' id="expander-2"> | ||
<label class="expander_label" for="expander-2">Simple Interest Formula »</label> | ||
<img src="simple-interest.png" alt="Simple Interest" | ||
style="height: 150px;"/> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
<div class="flexelement"> | ||
|
||
<div id="form" style=""> | ||
|
||
<div> | ||
<label>Principal | ||
<input id="principal" type="number" style="color: black; min-height: 60px;"/></label> | ||
<br/><br> | ||
FabioRosado marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<label>Interest rate | ||
<input id="interest_rate" type="number" style="color: black; min-height: 60px;" | ||
placeholder="Decimal, f.e. 0.8"/> | ||
</label> | ||
<br> | ||
<br/> | ||
|
||
<label>Time | ||
<input id="time" type="number" style="color: black; min-height: 60px;" | ||
placeholder="in years"/></label> | ||
<br> <br/> | ||
|
||
<button py-click="interest()" id="calc" style="min-height: 60px;" disabled>Calculate</button> | ||
|
||
<div style="margin-top: 2%;"> | ||
<span id="simple_interest"></span> | ||
<br/> | ||
<span id="compound_interest"></span> | ||
</div> | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
<py-config src="../py_config.toml"></py-config> | ||
<py-script src="calculator.py"></py-script> | ||
<py-script> | ||
setup() | ||
</py-script> | ||
</main> | ||
|
||
<footer> | ||
<p id="footer_p"> | ||
thank you for using the "Simple and Compound | ||
Interest Calculator!", powered by PyScript! | ||
</p> | ||
</footer> | ||
|
||
</body> | ||
|
||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Compound Interest Calculator | ||
subtitle: The classic hello world, but in Python -- in a browser! | ||
--- | ||
The *body* description. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
165 changes: 165 additions & 0 deletions
165
src/psc/gallery/examples/interest_calculator/styles.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
body { | ||
background-color: #F3F6F8; | ||
min-height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
main { | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
|
||
img { | ||
flex: 1; | ||
margin: 5%; | ||
margin-left: 20%; | ||
} | ||
|
||
#first_div { | ||
align-content: center; | ||
margin: 1%; | ||
flex: 1.25; | ||
} | ||
|
||
#first_p { | ||
margin: 3.5%; | ||
margin-left: 15%; | ||
font-family: Tahoma, sans-serif; | ||
} | ||
|
||
.flexelement { | ||
flex: 1; | ||
padding: 2%; | ||
} | ||
|
||
|
||
|
||
#form { | ||
margin-top: 7%; | ||
height: 100%; | ||
display: flex; | ||
align-content: center; | ||
justify-content: center; | ||
} | ||
|
||
#form input[type=number] { | ||
border: 1px solid white; | ||
border-radius: 0.3em; | ||
height: 12%; | ||
width: 100%; | ||
margin-bottom: 5px; | ||
} | ||
|
||
|
||
#form button { | ||
width: 100%; | ||
height: 12%; | ||
margin-bottom: 5px; | ||
} | ||
|
||
header { | ||
height: 100px; | ||
} | ||
|
||
footer { | ||
margin-top: auto; | ||
height: 57px; | ||
} | ||
|
||
header, footer { | ||
background-color: #1A1A27; | ||
} | ||
|
||
#header_h1 { | ||
padding-top: 2.2%; | ||
margin-left: 40%; | ||
font-weight: bold; | ||
color: white; | ||
} | ||
|
||
input[type=number] { | ||
padding: 1%; | ||
} | ||
|
||
#principal, #interest_rate, #time { | ||
width: 25%; | ||
} | ||
|
||
#calc { | ||
width: 25%; | ||
padding: 1%; | ||
font-weight: bold; | ||
margin-top: 2%; | ||
color: white; | ||
background-color: #0095E8; | ||
} | ||
|
||
#simple_interest, #compound_interest { | ||
color: black; | ||
font-weight: bold; | ||
} | ||
|
||
input[type=radio] { | ||
display: none; | ||
} | ||
|
||
label { | ||
cursor: pointer; | ||
} | ||
|
||
input[type=radio] ~ img { | ||
animation: close 1.5; | ||
display: none; | ||
height: 0; | ||
max-height: 500px; | ||
overflow: hidden; | ||
} | ||
|
||
input[type=radio]:checked ~ img { | ||
animation: open 1.5s; | ||
display: block; | ||
height: auto; | ||
max-height: 500px; | ||
} | ||
|
||
@keyframes open { | ||
from { | ||
max-height: 0; | ||
} | ||
|
||
to { | ||
max-height: auto; | ||
} | ||
} | ||
|
||
@keyframes close { | ||
from { | ||
display: block; | ||
max-height: auto; | ||
} | ||
|
||
to { | ||
display: none; | ||
height: 0; | ||
} | ||
} | ||
|
||
.expander_label { | ||
border: 1px solid #0095E8; | ||
border-radius: 0.1em; | ||
padding: 1%; | ||
font-weight: 500; | ||
color: white; | ||
background-color: #0095E8; | ||
background-color: #0095E8; | ||
} | ||
|
||
#footer_p { | ||
font-weight: bold; | ||
font-size: 13px; | ||
text-align: center; | ||
color: white; | ||
vertical-align: central; | ||
padding: 1.2%; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.