python - 如果用户输入 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 并且我不知道该怎么做,我是编码新手。
解决方案
推荐阅读
- angular - RXJS 在 forkJoin 可观察数组中捕获错误
- r - 如何根据矩阵位置计算总分?
- solr - 用于 Html 的 Solr 数据导入处理程序
- excel - 自动筛选与 ShowAllData
- javascript - 量角器黄瓜配置文件为我的场景抛出未定义的警告,即使这些场景存在
- python - 将 PySpark 中的两个 DataFrame 组合成矩阵
- apache-spark - 无法使用 Nifi 和 Schema Registry 使用 Kafka Avro 记录
- python - 如何根据python中的正确答案按递增顺序显示学生
- javascript - 如何使用 javascript 压缩图像,然后将其发送到 PHP 服务器?
- .net - 使用 Owin 会话 cookie 身份验证时如何为“AcquireTokenOnBehalfOf()”创建 UserAssertion