gpt4 book ai didi

python-3.x - python : Checking whether or not a variable is a int (using while loop)

转载 作者:行者123 更新时间:2023-12-02 04:44:56 24 4
gpt4 key购买 nike

只需要一点帮助。开始使用 Python,尝试创建一个高分程序,我想说当分数不等于整数时要求用户输入分数。

例如(这行不通)

name = input("Please enter your name: ")
score = None
while score != int(score):
score = input("Enter your score: ")
print("congratz it worked genius")

提前致谢

最佳答案

 while True:
try:
score = int(input("Enter your score: "))
break
except ValueError:
print("Int, please.")

关于python-3.x - python : Checking whether or not a variable is a int (using while loop),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19984168/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com