Program to print number range

This program prints range for a number entered by user

Number Range

First number range is between 0 to 10
Second number range is between 11 to 20
Third number range is between 21 to 30
Fourth number range is between 31 to 40
Fifth number range is between 41 to 50
Sixth number range is greater than 50

`num = int(input('Enter any number: '))`

Using condition check to determine range for a entered number

`if num <= 10:    print('Entered number is between 0 to 10')elif 10 < num <= 20:    print('Entered number is between 11 to 20')elif 20 < num <= 30:    print('Entered number is between 21 to 30')elif 30 < num <= 40:    print('Entered number is between 31 to 40')elif 40 < num <= 50:    print('Entered number is between 41 to 50')else:    print('Entered number is greater than 50')`

Output

``````Enter any number: 0
Entered number is between 0 to 10``````

Output

``````Enter any number: 66
Entered number is greater than 50``````

Output

``````Enter any number: 45
Entered number is between 41 to 50``````

Output

``````Enter any number: 25
Entered number is between 21 to 30``````

Complete Code

`try:    num = int(input('Enter any number: '))    if num <= 10:        print('Entered number is between 0 to 10')    elif 10 < num <= 20:        print('Entered number is between 11 to 20')    elif 20 < num <= 30:        print('Entered number is between 21 to 30')    elif 30 < num <= 40:        print('Entered number is between 31 to 40')    elif 40 < num <= 50:        print('Entered number is between 41 to 50')    else:        print('Entered number is greater than 50')except ValueError:    print('Invalid Number')`

Program uses try and except and will display message ‘Invalid Number’ incase user enter some alphanumeric character instead of number