gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 21:43:21 25 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/

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