我希望代码在用户输入字符串而不是整数时捕获错误。您可以看到我尝试了一个仍然无法正常工作的 try catch 块。除此之外,其他一切都很完美。我该如何解决这个问题?
这是输出应该如何:
Welcome to the Squares and Cubes table
Enter an integer: five
Error! Invalid integer. Try again.
Enter an integer: -5
Error! Number must be greater than 0
Enter an integer: 101
Error! Number must be less than or equal to 100
Enter an integer: 9
Number Squared Cubed
====== ======= =====
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
Continue? (y/n): y
Enter an integer: 3
Number Squared Cubed
====== ======= =====
1 1 1
2 4 8
3 9 27
米脂
三国纷争
慕运维8079593
相关分类