Is it possible to request python to do a range check for numbers?

Viewed 21

I'm struggling with some homework and basically I want to do something like this...

def house_cleaning(num1, num2):
mult = num1 * num2
return mult
x = int(input('How many rooms are in your house? '))
y = int(input('type "4" for light cleaning service or type "8" for heavy cleaning service '))



if x == 4 to 5:
print('Your house is small sized.')
house_size = 'small'
elif x == 6 to 7:
print('Your house is medium sized.')
house_size = 'medium'
elif x > 8:
print('Your house is large sized.')
house_size = 'large'

I want the code to run as it checks if the user enters a number 4-5 then it'll print the house is small and so on and so forth. Is this possible? Whenever I do the < signs I Just get a fail.

1 Answers

You can check if a number is within a range in the following way:

if 4 <= x <= 5:
    print('Your house is small sized.')

You can read more about this here.

Related