zoukankan      html  css  js  c++  java
  • TypeError: '

    1、错误描述

    >>> num=input('请输入一个整数:');
    请输入一个整数:78
    >>> if num  < 10:
    	num=10;
    	print("你输入的整数小于10");
    	elif num < 20:
    		
    SyntaxError: invalid syntax
    >>> if num<10:
    	num=10;
    	print("小于10");
    elif num < 20:
    	num=20;
    	print("小于20");
    else:
    	print(num);
    
    	
    Traceback (most recent call last):
      File "<pyshell#13>", line 1, in <module>
        if num<10:
    TypeError: '<' not supported between instances of 'str' and 'int'
    >>> 

    2、错误原因

         利用input()提示输入的内容是一个字符串,字符串跟整型数值进行比较,类型不匹配导致报错


    3、解决办法

         在提示输入时,利用int()将字符串转换成整型

         num=int(input('请输入一个整数:'));

  • 相关阅读:
    关于asp.netCore3.0区域和路由配置
    用Autofac替换.net core 内置容器
    C#Assembly详解
    MongoDB
    Python
    Python,正则表达式
    Python
    Python
    Gevent和猴子补丁
    Django
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13313882.html
Copyright © 2011-2022 走看看