- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
") if age >= 24: print("you are getting old") print (age) els-6ren">
print("how old are you")
age = input(">")
if age >= 24:
print("you are getting old")
print (age)
else:
print("i don't care")
print (age)
这是我遇到的错误:
if age >= 24:
TypeError: unorderable types: str() >= int()
最佳答案
在 Python 3 上,input()
总是 返回一个字符串值。使用 int()
type转换它:
if int(age) >= 24:
字符串值和 int 不可排序:
>>> '24' > 23
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: str() > int()
请注意,如果无法转换输入,int()
会抛出一个ValueError
异常:
>>> int('Why do you want to know my age?')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'Why do you want to know my age?'
关于 python 3.3.2 年龄 >= 24 : TypeError: unorderable types: str() >= int(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18262398/
你好,我正在编写和测试一个递归动态编程背包(0-1)(以下代码是主文件和函数)我不断收到错误(在代码之后发布)...我真的对于错误是什么感到困惑,因此我们将不胜感激任何帮助! 主文件 import K
我正在尝试对对象列表进行排序,但收到以下错误: subredditlist.sort(key=lambda x: x.count) TypeError: unorderable types: bu
我不断收到错误unorderable types: list() main() File "command.py", line 12, in main if numbers[i]>
我在尝试执行 Python 程序时不断收到此错误。该程序的要点是不断滚动一组骰子,直到用户输入小于 0 的数字。 import random num_sixes = 0 num_sevens = 0
我正在尝试用 python 制作一个乒乓球风格的游戏,但每次我都会收到标题中写的错误。我已经尝试过谷歌搜索方法来修复错误,但我没有地方开始。我的距离函数可能不起作用。但任何东西都可能被破坏,所以任何帮
这个问题已经有答案了: Add tkinter's intvar to an integer (2 个回答) 已关闭 5 年前。 我正在尝试在 python 上制作一个答题器游戏,但我不断收到错误 "
我有一个由两个函数组成的代码,一个函数读取数据,另一个函数计算数据。两个函数单独运行时都可以正常运行,但是当我尝试让计数器调用文件读取器时出现错误。如果有人能告诉我我哪里搞砸了,我将不胜感激。提前致谢
使用IPtools python 包我试图查看 IP 地址是否在特定范围内。这是我的代码: for line in g: org= line.split("|")[0] ranges
我有这段代码在 python 2.7 中运行良好。“dist”是数字字典,“min_dist”只是一个数字。 for v in vertices: if dist[v.node_id] >>
这个问题在这里已经有了答案: Why do I get "Unorderable types: int() int() 当我运行下面的代码时。我刚开始学python number = input(
我是 python3 的新手,在尝试读取昨天的地震数据时遇到以下错误!! Traceback (most recent call last): File "Z:\Python learning\U
下面的 Python 片段给我一个错误: df = pandas.DataFrame({'A': ['UBS','UBS','ABB','UBS'], 'B': ['L', 'L', 'L', 'D'
在 Python 中,我正在实现 A* 搜索算法来解决拼贴问题。我有以下 Node 类,它将状态保存为元组的元组。例如初始状态是: initial= ((7,2,4),(5,0,6),(8,3,1))
我使用的是 python 3.5,所有包都是以下版本 numpy-1.12.0b1+mkl-cp35-cp35m-win_amd64 scikit_learn-0.18.1-cp35-cp35m-wi
from urllib.request import urlopen page1 = urlopen("http://www.beans-r-us.biz/prices.html") page2 =
我有一个 csv 文件和 v3 列,但该列有一些“nan”行。我怎样才能排除行。 dataset = pd.read_csv('mypath') enc = LabelEncoder()
我正在尝试开发程序,但是错误似乎让我反复受到欢迎 TypeError: unorderable types: list() <= int() 当我彼此之间执行2个if循环时,会发生这种情况。为了给问题
@commands.command(pass_context=True) @checks.serverowner() async def change(self, ctx, change):
如果我写 from ggplot import * import matplotlib.pyplot as plt plt.figure() ggplot(aes(x='date_hour', y='
我正在移植适用于 python2 的代码。移植时出现错误 unorderable types: dict() `color` is a 我怎样才能使它在 python3 中工作? 最佳答案 你根本
我是一名优秀的程序员,十分优秀!