Get user input as int or str

后端 未结 2 1695
情歌与酒
情歌与酒 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:53

    choice = raw_input("Select a monitoring plot from the list: ")
    
    if choice == 'q':
        break
    
    plotSelect = int(choice)
    selected = dataList[plotSelect+1]
    

    Check if the user entered q and explicitly break out of the loop if they do (rather than relying on an exception being thrown). Only convert their input an int after this check.

提交回复
热议问题