首页 > 解决方案 > 如果用户输入 str 而不是 int,我试图返回 false

问题描述

def playerTurn(ballCount):
    playerchoice = int(input("How many balls do you want"))
if playerchoice == playerchoice.isalpha():
    print("has to be a number")
    return False
ballCount = ballCount - playerchoice
if playerchoice == 0:
    print("you cant choose 0")
    

#这是我尝试过的,但是输入已经是 int 并且我不知道该怎么做,我是编码新手。

标签: pythonstringif-statementinputinteger

解决方案


推荐阅读