Skip to content

Instantly share code, notes, and snippets.

@chinmay29hub
Created May 8, 2022 04:57
Show Gist options
  • Save chinmay29hub/d713d529c55d117d59326c164eac68ad to your computer and use it in GitHub Desktop.
Save chinmay29hub/d713d529c55d117d59326c164eac68ad to your computer and use it in GitHub Desktop.
A simple pyscript for factorial
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<style>
#output {
color: rgb(31, 35, 221);
font-size: 70px;
}
</style>
</head>
<body>
<div id="output"></div>
<py-script>
num = 7
factorial = 1
if num < 0:
pyscript.write('output', f'Sorry, factorial does not exist for negative numbers')
elif num == 0:
pyscript.write('output', f'The factorial of {num} is {factorial}')
else:
for i in range(1,num + 1):
factorial = factorial*i
pyscript.write('output', f'The factorial of {num} is {factorial}')
</py-script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment