-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVanderheyden_pythonGuessingGame.html
44 lines (39 loc) · 1.07 KB
/
Vanderheyden_pythonGuessingGame.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
<style>
label{
display:block;
}
</style>
</head>
<body>
<py-config>
packages = ['numpy']
</py-config>
<py-script>
import numpy as np
selection = np.random.randint(0,100,1)[0]
</py-script>
<form>
<label for="guess">Guess:</label><input name="guess" id="guess">
<button type="button" id="submit">Check Guess</button>
<label for="result">Result:</label><div name="result" id="result"></div>
</form>
<py-script>
from pyscript import when
@when("click", selector="#submit")
def check_guess():
user_guess = int(Element("guess").value)
result = Element("result")
if user_guess == selection:
result.write("Congratulations! You guessed correctly.")
elif user_guess > selection:
result.write("Try again! Your guess was too high.")
else:
result.write("Try again! Your guess was too low.")
</py-script>
</body>
</html>