[英]Flask TypeError: '<' not supported between instances of 'str' and 'int'
I'm trying to learn Flash by doing exercise, but I got an error "TypeError: '<' not supported between instances of 'str' and 'int'".我正在尝试通过练习来学习 Flash,但出现错误“TypeError: '<' not supported between 'str' and 'int'”。
from flask import Flask
app = Flask(__name__)
@app.route('/fib/<int:n>/')
def fibo(n):
n = format(n)
if n < 2:
return 1
return fibo(n -1) + fibo(n -2)
You are trying to make a mathematical comparison between a string and an integer.您正在尝试在字符串和整数之间进行数学比较。 You need to convert n to a number before comparing it to see if it is less than 2. This means changing
format(n)
to some other function to convert n to a number.在比较 n 是否小于 2 之前,您需要将 n 转换为数字。这意味着将
format(n)
更改为其他函数以将 n 转换为数字。
Please mark as correct if this helps.如果这有帮助,请标记为正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.