当用户输入无效输入

时间:2015-04-30 03:02:22

标签: python-3.x

我试图获得连接4游戏板的列数和行数必须是5乘5.如果用户输入字符串或数字,我需要重复输入问题低于5.这就是我所拥有的

    rows =  0
    columns = 0

    print("Please enter the number of rows: ", end = "")
    while rows < 5:
        try:
            rowsInput = input()
            rows = int(rowsInput)
        except ValueError:
            print("Please enter a valid choice: ", end = "")

    print("Please enter the number of columns: ", end = "")
    while columns < 5:
        try:
            colInput = input()
            columns = int(colInput)
        except ValueError:
            print("Please enter a valid choice: ", end = "")

这适用于字符串但是当我输入一个小于5的数字时,它会显示为空白,因为它只询问rowsInput = input()但我希望它打印出Please enter a valid choice:用户输入字符串和小于5的数字。任何想法?

1 个答案:

答案 0 :(得分:0)

function splitCells2() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
  var colC = sheet.getRange(2, 3, sheet.getLastRow()).getValues();  // C2:C, only non-blank rows
  //Logger.log(colC);
  for(var i=0; i< colC.length; i++){
    if(colC[i][0] != ''){
      // If we received a SMS response, set a formula to parse it
      sheet.getRange(2+i,4).setValue('=if(istext(C2:C),split(C2:C,",",true),"")')
    }
  }
}