Python reports TypeError: & #39; & lt; & #39; not supported between instances of & #39; str & #39; and & #39; int & #39 ;, pythontypeerror

Source: Internet
Author: User

Python reports TypeError: '<'not ororted between instances of 'str' and 'int', pythontypeerror

1 n = input () 2 if n >=100: print (int (n)/10) 3 else: print (int (n) * 10)

Error message:


Traceback (most recent call last): File "", line 12, in <module> if n >=100: print (int (n)/10) TypeError: '> =' not supported between instances of 'str' and 'int' *** Repl Closed ***



Analysis: the data type returned by input () is str, which cannot be directly compared with an integer. You must replace str with an integer and use the int () method.

Therefore, convert the input variable to the int type.

1 n = input () 2 n = int (n) 3 if n> = 100: print (int (n)/10) 4 else: print (int (n) * 10)




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.