how do i add limitations in inputs in python

Solutions on MaxInterview for how do i add limitations in inputs in python by the best coders in the world

showing results for - "how do i add limitations in inputs in python"
Niklas
21 May 2016
1hp_cur=int(input("Enter the current number of HP (1-75): "))
2hp_max= int(input("Enter the maximum number of HP (1-75): "))
3hp_dif=(hp_max-hp_cur)
Kelyan
07 Jul 2018
1while True:    
2    try:
3        hp_cur=int(input("Enter the current number of HP (1-75): "))
4    except ValueError: # used to check whether the input is an int
5        print("please insert a int type number!")
6    else: # is accessed if the input is a int
7        if hp_cur < 1 or hp_cur > 75:
8            print("please insert a number in the given limit")
9        else: # if number is in limit, break the loop
10            break