Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python中正确使用小于和大于符号_Python - Fatal编程技术网

如何在Python中正确使用小于和大于符号

如何在Python中正确使用小于和大于符号,python,Python,因此,我的脚本中有以下函数: def age(): global age age = raw_input("Age: ") if age == 14: sleep(1) print ("LOL, same") elif age < 18: sleep(1) print ("This test is made for contestan

因此,我的脚本中有以下函数:

def age():
    global age
    age = raw_input("Age: ")

    if age == 14:
        sleep(1)
        print ("LOL, same")
    
    elif age < 18:
        sleep(1)
        print ("This test is made for contestants older than ten")
        introduction()  
        
    elif age > 18:
        sleep(1)
        print ("Geez grandpa, you sure are old")
def age():
全球时代
年龄=原始输入(“年龄:”)
如果年龄=14岁:
睡眠(1)
打印(“LOL,相同”)
elif年龄<18岁:
睡眠(1)
打印(“此测试针对10岁以上的参赛者进行”)
导言()
elif年龄>18岁:
睡眠(1)
打印(“天哪,爷爷,你真老了”)
当我运行此程序时,它会将我键入的每个年龄记录为18岁以上,如下所示:

你能告诉我你的年龄吗

年龄:4

哎呀,爷爷,你真老了


为什么会这样做?

原始输入
以字符串类型返回用户输入时,应将其转换为int

更改此项:

age = raw_input("Age: ")
致:


您的原始输入被视为字符串

age = raw_input("Age: ")
因此,如果要将其与数字进行比较,则需要将其转换为整数值

age = int(raw_input("Age: "))

age=raw\u输入(“age:”)
更改为
age=int(raw\u输入(“age:”)
raw\u input
的结果是一个字符串,Python 2.7允许您将其与
int
raw\u input()进行比较。
返回一个字符串,而不是整数。如果要将其与其他整数进行比较,必须先对其进行转换。请参阅副本。您应该使用Python 3;它不会在这些类型的错误上无声地失败。先生,我需要和你谈谈,我们可以聊天吗?是的,没问题@SurajJainCan你能创建聊天吗?
age = int(raw_input("Age: "))