我正在尝试编写一个程序,确保用户只能在 input() 中输入数字。我写了以下代码:
price = input("Enter price of movie: $")
while type(price)!=float:
print("Please enter numbers only")
price = input("Enter price of movie: $")
然而,无论我输入的是字符串、整数还是浮点数,这都会产生无限循环。
我可以知道如何解决这个问题吗?
提前致谢