Getting an Integer Input in a Range

后端 未结 5 470
鱼传尺愫
鱼传尺愫 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:07

    The test "next == int in range(50)" evaluates to "(next == int) and (int in range(50))" which is fairly meaningless and always equates to false.

    Instead you could try

    try:
        how_much = int(next)
        if not (0<=how_much<50):
           print 'Too greedy'
    except ValueError:
        dead("Man, learn how to type a number.")
    

提交回复
热议问题