Getting an Integer Input in a Range

后端 未结 5 537
鱼传尺愫
鱼传尺愫 2021-01-03 11:30

I\'m trying to take a raw input and detect whether it is in a range.
Here\'s my code.

def gold_room():
    print \"This room is full of gold. How much          


        
5条回答
  •  渐次进展
    2021-01-03 12:09

    Using try .. except will allow you to make sure entered value is an int. # raise is a place holder for your handling a non-int contition:

    try:
        next = int(raw_input("> "))
    except ValueError:
        # raise
    
    if not 0 <= next <= 50:
        print 'Too greedy'
    

提交回复
热议问题