# 軟實作業

```=python
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method= 'post' action= "/">
<input type='text' name='username'>
<button type='submit'>submit</button>
</form>
</body>
</html>
```

```=python
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route("/", methods=['GET', 'POST'])
def submit():
if request.method == 'POST':
return 'Hello' + request.values.get('username')
return render_template('post_submit.html')
if __name__ == '__main__':
app.debug = True
app.run()
```

```=python
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method= 'post' action= "/">
<p>微分</p>
<p>輸入:x**2,2*x</p>
<input type = 'text' name = 'username'>
<button type = 'submit'>submit</button>
</form>
</body>
</html>
```

```=python
from flask import Flask, request, render_template
import sympy as sp
from sympy import *
app = Flask(__name__)
@app.route("/", methods=['GET', 'POST'])
def submit():
if request.method == 'POST':
x = sp.symbols('x')
ss = request.values.get('username')
tt = "diff(" + ss + ")"
ans = eval(tt)
return '函數'+ss+ '的微分: ' +str(ans)
return render_template('post_submit2.html')
if __name__ == '__main__':
app.debug = True
app.run()
```

```=python
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>多項式相加網頁</title>
</head>
<body>
<form method = 'post' action = "/">
<p>多項式相加<p>
<p>f(x):</p>
<input type='text' name='username1'>
<p>g(x):</p>
<input type='text' name='username2'>
<input type='Radio' name='gender' value ='add'>Add
<input type='Radio' name='gender' value ='sub'>Sub
<button type='submit'>按鍵傳送</button>
</form>
```

```=python
from flask import Flask, request, render_template
import sympy as sp
from sympy import *
app = Flask(__name__)
@app.route("/", methods=['GET','POST'])
def submit():
if request.method == 'POST':
x = sp.symbols('x')
ss1 = request.values.get('username1')
ss2 = request.values.get('username2')
op = request.values.get('gender')
if op == "add":
tt = "("+ss1+")"+"+"+"("+ss2+").simplify()"
op = "+"
else:
tt = "(" + ss1 + ")" + "-" + "(" + ss2 + ").simplify()"
op = "-"
ans = eval(tt)
return "("+ss1+")"+op+"("+ss2+")"+' => '+str(ans)
return render_template('001.html')
if __name__ == '__main__':
app.debug = True
app.run()
```