[英]how do i run multiple lines of python in html
I am trying to figure out how to run multiple lines of code from python in html我试图弄清楚如何从 html 中的 python 运行多行代码
So far i have:到目前为止,我有:
<!DOCTYPE html>
<html>
<py-script>
print()
print("Select The Corresponding Number Or Word For The Operation To Perform:")
print("Type 'quit' To Quit")
print("1. ADD")
operation = input().lower()
# --- ADD --- #
if operation == "1" or operation == "add":
addend1 = float(input("Enter The First Number: "))
addend2 = float(input("Enter The Second Number: "))
print("The Result Is ", str(addend1 + addend2))
<py-script>
</html>
The output is: output 是:
print() print("Select The Corresponding Number Or Word For The Operation To Perform:") print("Type 'quit' To Quit") print("1. ADD") print("2. SUBTRACT") print("3. MULTIPLY") print("4. DIVIDE") operation = input().lower() # --- ADD --- # if operation == "1" or operation == "add": addend1 = float(input("Enter The First Number: ")) addend2 = float(input("Enter The Second Number: ")) print("The Result Is ", str(addend1 + addend2)) # --- SUBTRACT --- # elif operation == "2" or operation == "subtract": number1 = int(input("Enter the first number")) number2 = int(input("Enter the second number")) print("The Diffrence Is ", str(number1 - number2)) # --- MULTIPLY --- # elif operation == "3" or operation == "multiply": multiplicand = float(input("Enter The First Number: ")) multiplier = float(input("Enter The Second Number: ")) print("The Product Is ", str(multiplicand * multiplier)) # --- DIVIDE --- # elif operation == "4" or operation == "divide": dividend = float(input("Enter The First Number print() print("选择要执行的操作的对应数字或单词:") print("键入 'quit' 退出") print("1.ADD") print("2.SUBTRACT") print(" 3. MULTIPLY") print("4.DIVIDE") operation = input().lower() # --- ADD --- # if operation == "1" or operation == "add": addend1 = float( input("输入第一个数字:")) addend2 = float(input("输入第二个数字:")) print("结果是", str(addend1 + addend2)) # --- SUBTRACT --- # elif operation == "2" or operation == "subtract": number1 = int(input("输入第一个数字")) number2 = int(input("输入第二个数字")) print("差异是" , str(number1 - number2)) # --- MULTIPLY --- # elif operation == "3" or operation == "multiply": multiplicand = float(input("Enter The First Number: ")) multiplier = float (input("输入第二个数字:")) print("积是", str(multiplicand * multiplier)) # --- DIVIDE --- # elif operation == "4" or operation == "divide" : 股息 = float(input("输入第一个数字: ")) divisor = float(input("Enter The Second Number: ")) print("The Result Is ", str(dividend / divisor))
: ")) divisor = float(input("输入第二个数字:")) print("结果是", str(dividend / divisor))
Please note that i copy and pasted the output and it is writen on one line on the website请注意,我复制并粘贴了 output,它写在网站上的一行上
I don't know what i am doing that well because this is one of my first times using 'pyscript' so if you could explain something that i haven't been able to find i would be great full我不知道我做得很好,因为这是我第一次使用“pyscript”,所以如果你能解释一些我找不到的东西,我会很高兴
You're looking for "PyScript".您正在寻找“PyScript”。 Python code inside HTML tags
HTML 标签内的 Python 代码
Your example does not include the PyScript framework.您的示例不包括 PyScript 框架。 Notice the two lines in the
<head>
tag.注意
<head>
标记中的两行。
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body>
<py-script>
# Insert Python code here ...
</py-script>
</body>
</html>
Note:You must interface with the browser DOM to get user input.注意:您必须与浏览器 DOM 交互才能获取用户输入。 When writing PyScript you must code to the browser interface and not to a command shell interface.
编写 PyScript 时,您必须对浏览器界面进行编码,而不是对命令 shell 界面进行编码。 Some Python APIs will not work in the browser.
某些 Python API 无法在浏览器中运行。
You cannot use code like this.你不能使用这样的代码。
operation = input().lower()
I wrote 18 articles on PyScript that might help you get started.我写了 18篇关于 PyScript 的文章,可能会帮助您入门。 Lots of example code with explanations.
大量带有解释的示例代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.