1

I am working on a website which will take input and do some calculations and give output. I need to write this calculation code in python. But since this will be used by other users, I want it to be in form of a website so I can deploy it.

Just like we can embed JavaScript code into a html page, can we do the same thing with python?? the code will be very simple, around 5-10 calculations. I know there are ways to do this with Flask or Django, but I was wondering if there was an easier way by just embedding python code in the HTML file.

Would it be better if I just create a Tkinter GUI web-app & turn it into an executable file?

below is the type of code I'll use on the website. Of course, the real code will be a little more complex and longer. But basically ill be asking for input and do calculations with it & then print the output

Example Python code

Length  = input(int("Insert the Length"))
Width =  input(int("Insert the Width"))
Print("area  of this rectangle is: "+ Length * Width)
davidism
  • 121,510
  • 29
  • 395
  • 339
Mhcg233366
  • 75
  • 6

4 Answers4

1

HTML + Javascript works, from https://www.w3resource.com/javascript-exercises/javascript-basic-exercise-10.php

<form>
Insert the Length <input type="text" id="firstNumber" /><br>
Insert the Width <input type="text" id="secondNumber" /><br>
<input type="button" onClick="multiplyBy()" Value="Multiply" />
</form>
<p>area  of this rectangle is: <br>
<span id = "result"></span>
</p>

And

function multiplyBy()
{
        num1 = document.getElementById("firstNumber").value;
        num2 = document.getElementById("secondNumber").value;
        document.getElementById("result").innerHTML = num1 * num2;
}
alvas
  • 115,346
  • 109
  • 446
  • 738
1

I think you should use Javascript in order to do this. According to what I know so far, Python can't be used that way like javascript.

0

You should probably do this in JS, since Python is quite a hassle to get to work in HTML. If you want you could do this in a tkinter web app, but you should probably use the <input> tag and do the calculations in JS. There is a lot of info online about this tag and how to use buttons in HTML.

coderman1234
  • 210
  • 3
  • 12
0

To my knowledge, you can't run python client-side using just HTML like with javascript, owing to the fact it is purely "server-side".