0% found this document useful (0 votes)
24 views5 pages

Lab 5-CHILESHE

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views5 pages

Lab 5-CHILESHE

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

THE COPPERBELT UNIVERSITY

SCHOOL OF MINES AND MINERAL SCIENCES


GEOMATICS DEPARTMENT
PYTHON FOR THE WEB
LAB 5

NAME : CHILESHE CHILIMA

SIN : 22997565

COURSE CODE : GE 360

COURSE NAME : COMPUTING FOR GEOMATICS

PROGRAMME : BACHELORS OF ENGINEERING IN GEOMATICS ENGINEERING

LECTURER : EB

DUE DATE : 5TH AUGUST, 2024.

1|Page
INTRODUCTION

This assignment explores the intersection of Python and web development. We will delve into
how Python, specifically with libraries like NumPy, Matplotlib, and PyScript, can be utilized to
create dynamic and interactive web applications. Through practical examples, we will
demonstrate how to embed Python code directly into HTML pages, generate data visualizations,
and enhance user experiences.

WORKFLOW

<html>
<head>
<title>CHILESHE CHILIMA</title>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>

<py-env>
- matplotlib
</py-env>
</head>

<body>
<h1 style="text-align: center; color: white; background-color: #FA2B6D">
Chileshe Chilima </h1>
<p style="font-weight: bold;">I am a 3rd year student at Copperbelt
University, Solwezi Satellite campus, pursuing a BEng in Geomatics
Engineering.</p>
<p>I have been assigned to do a lab in Python for the web and this is
what I have done.</p>

<label> Enter Number </label> <br>


<input type="number" name="" id="evenOdd" onkeyup="isCheck()">
<span id="showMssg" style="color: #342BFA;"> </span>
</br><br>

<label> Enter Number </label> <br>


<input type="number" name="" id="evenOdds" onkeyup="isChecks()">
<span id="showMssgs" style="color: #FA2B44;"> </span>

<script>

2|Page
function isCheck(){
var num = document.getElementById('evenOdd').value;
// alert(num);
if((num%2) == 0){
document.getElementById('showMssg').innerHTML = "Wow! Number
"+num+" is an even number";
}
else{
document.getElementById('showMssg').innerHTML = "Oo No! "+num+" is
not an even number";
}

if(num === ""){


document.getElementById('showMssg').innerHTML = "";
}
}

function isChecks(){
var num = document.getElementById('evenOdds').value;
// alert(num);
if((num%2) == 0){
document.getElementById('showMssgs').innerHTML = "Wow! Number
"+num+" is an even number";
}
else{
document.getElementById('showMssgs').innerHTML = "Oo No! "+num+" is
not an even number";
}

if(num === ""){


document.getElementById('showMssgs').innerHTML = "";
}
}

</script>

<div id="plot"></div>
<py-script output="plot">
import matplotlib
import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0.0, 2.0, 0.01)


s = 1 + np.sin(2 * np.pi * t) # Indentation added
fig, ax = plt.subplots()

3|Page
ax.plot(t, s)

ax.set(xlabel='time (s)', ylabel='voltage (mV)',


title='A Graph of time(s) against voltage(mV)')
ax.grid()

fig
</py-script>
</body>
</html>

RESULT OBTAINED

4|Page
CONCLUSION

This exploration has demonstrated the power of Python in web development, particularly when
combined with libraries like NumPy, Matplotlib, and PyScript. By seamlessly integrating Python
code into HTML, we've seen how to create interactive visualizations and dynamic web
applications. This approach opens up new possibilities for data scientists, educators, and
developers alike.

PyScript, as a relatively new framework, shows immense promise. Its ability to bridge the gap
between Python and the web is a game-changer. With continued development and community
support, PyScript has the potential to revolutionize how we build web applications, making data-
driven insights more accessible and engaging. As the technology matures, we can anticipate even
more sophisticated and performant applications emerging from this powerful combination.

5|Page

You might also like