from flask import Flask, request, render_template_string
app = Flask(__name__)
# 定义 HTML 模板,加入居中样式
template = '''
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Find Numbers</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
}
.container {
text-align: center;
width: 300px;
padding: 20px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
h2 {
font-size: 1.5em;
margin-bottom: 20px;
}
input[type="number"], input[type="submit"] {
padding: 8px;
font-size: 1em;
width: 100%;
margin-top: 10px;
margin-bottom: 10px;
box-sizing: border-box;
}
</style>
</head>
<body>
<div class="container">
<h2>请输入一个整数 n:</h2>
<form method="POST">
<input type="number" name="n" required>
<input type="submit" value="提交">
</form>
{% if result is not none %}
<h3>满足条件的数字列表为:</h3>
<p>{{ result }}</p>
{% endif %}
</div>
</body>
</html>
'''
def find_numbers(n):
result = []
for num in range(1, n + 1):
digits = [int(d) for d in str(num)]
product = 1
for d in digits:
product *= d
if product > sum(digits):
result.append(num)
return result
@app.route("/", methods=["GET", "POST"])
def index():
result = None
if 网页链接 == "POST":
n = int(request.form["n"])
result = find_numbers(n)
return render_template_string(template, result=result)
if __name__ == "__main__":
app.run(debug=True)
app = Flask(__name__)
# 定义 HTML 模板,加入居中样式
template = '''
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Find Numbers</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
}
.container {
text-align: center;
width: 300px;
padding: 20px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
h2 {
font-size: 1.5em;
margin-bottom: 20px;
}
input[type="number"], input[type="submit"] {
padding: 8px;
font-size: 1em;
width: 100%;
margin-top: 10px;
margin-bottom: 10px;
box-sizing: border-box;
}
</style>
</head>
<body>
<div class="container">
<h2>请输入一个整数 n:</h2>
<form method="POST">
<input type="number" name="n" required>
<input type="submit" value="提交">
</form>
{% if result is not none %}
<h3>满足条件的数字列表为:</h3>
<p>{{ result }}</p>
{% endif %}
</div>
</body>
</html>
'''
def find_numbers(n):
result = []
for num in range(1, n + 1):
digits = [int(d) for d in str(num)]
product = 1
for d in digits:
product *= d
if product > sum(digits):
result.append(num)
return result
@app.route("/", methods=["GET", "POST"])
def index():
result = None
if 网页链接 == "POST":
n = int(request.form["n"])
result = find_numbers(n)
return render_template_string(template, result=result)
if __name__ == "__main__":
app.run(debug=True)