A Pen by Takuma KATANOSAKA on CodePen.
Created
June 7, 2022 01:41
-
-
Save rcdevgames/a65d48e0152f9cac98cf1ece7d5c8680 to your computer and use it in GitHub Desktop.
PyScript Sample
This file contains 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
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>PyScript Test</title> | |
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" /> | |
<script defer src="https://pyscript.net/alpha/pyscript.js"></script> | |
<script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,line-clamp"></script> | |
</head> | |
<body> | |
<header> | |
<h1 class="text-3xl font-bold underline"> | |
PyScript Sample Page | |
</h1> | |
</header> | |
<main> | |
<div class="prose"> | |
<p> | |
Today is <u><label id='today'></label></u> | |
</p> | |
<p> | |
If you want to get more information, please click <a href="https://github.com/pyscript/pyscript/blob/main/GETTING-STARTED.md" target="_blank" rel="noopener noreferrer">this link</a>. | |
</p> | |
<h2>Your Settlement Amount</h2> | |
<table> | |
<thead> | |
<tr> | |
<th> | |
Item | |
</th> | |
<th> | |
Value | |
</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td> | |
Price | |
</td> | |
<td> | |
¥<label id="price"></label> | |
</td> | |
</tr> | |
<tr> | |
<td> | |
Tax Rate | |
</td> | |
<td> | |
<label id="tax_rate"></label>% | |
</td> | |
</tr> | |
<tr> | |
<td> | |
Tax Price | |
</td> | |
<td> | |
¥<label id="tax_price"></label> | |
</td> | |
</tr> | |
<tr> | |
<td> | |
Total Price | |
</td> | |
<td> | |
¥<label id="total_price"></label> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
<py-script> | |
import datetime as dt | |
import random | |
import math | |
price = 1300 | |
ceil_digit = 3 | |
tax_rate = math.ceil(random.random() * 10 ** ceil_digit) / (10 ** ceil_digit) | |
tax_price = math.ceil(price * tax_rate) | |
total_price = math.ceil(price + tax_price) | |
pyscript.write('today', dt.date.today().strftime('%A %B %d, %Y')) | |
pyscript.write('price', price) | |
pyscript.write('tax_rate', tax_rate * 100.0) | |
pyscript.write('tax_price', tax_price) | |
pyscript.write('total_price', total_price) | |
</py-script> | |
</div> | |
</main> | |
<footer> | |
©️2022 Takuma Katanosaka | |
</footer> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment