Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

TypeError: '<' not supported between instances of 'str' and 'int'

i am just experimenting while loop and what i am trying to do is to make the user input his Hight and it should be bigger than zero but when the user input number less than 0 two time the following error show:

TypeError: '<' not supported between instances of 'str' and 'int'

so what wrong with my code?

import sys

def two_by_two(num1, num2):
    val = num1 * num2
    return val
hight = input("what is your hight?  ")
hight = int(hight)
attempt_count = 1
while hight < 0:
    if attempt_count > 3:
        sys.exit("too  many")
    hight = input("The number bigger than ZERO, what is your hight?  ")
    attempt_count += 1

print(two_by_two(hight, 5))

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,716 Points

I like your approach to this, nice work!

You only forgot one tiny thing (and you may have discovered it already). Convert the second input to an integer (see below).

Cheers to you! JM

import sys

def two_by_two(num1, num2):
    val = num1 * num2
    return val
hight = input("what is your hight?  ")
hight = int(hight)
attempt_count = 1
while hight < 0:
    if attempt_count > 3:
        sys.exit("too  many")
    hight = input("The number bigger than ZERO, what is your hight?  ")
    hight = int(hight) # this was added to do the conversion.
    attempt_count += 1

print(two_by_two(hight, 5))

Thank you I highly appreciate your help and your encouragement for me :)