Get user input as int or str

后端 未结 2 1676
情歌与酒
情歌与酒 2021-01-26 19:18

I\'m very new to python and believe me, I\'ve searched endlessly for a solution to this but I just can\'t get it.

I have a csv with a list of monitoring plots. With the

2条回答
  •  春和景丽
    2021-01-26 19:56

    Convert it into an integer after you check that it's not 'q':

    try:
        response = raw_input("Select a monitoring plot from the list: ")
    
        if response == 'q':
            break
    
        selected = dataList[int(plotSelect) + 1]
    
        print 'You selected : ', selected[1]
        break
    except ValueError:
        print "Error: Please enter a number between 0 and 9"
    

提交回复
热议问题