我一直在尝试在Python上做一个对数计算器。我离完成它只有一步之遥。代码如下:import math
print("Welcome to logarithm calculator")
while True:
try:
inlog = int(input("Enter any value greater than zero to lookup its logarithm to the base 10\n"))
outlog = math.log(inlog, 10)
print(outlog)
# Here, the program will ask the user to quit or to continue
print("Want to check another one?")
response = input("Hit y for yes or n for no\n")
if response == ("y" or "Y"):
pass
elif response == ("n" or "N"):
break
else:
#I don't know what to do here so that the program asks the user to quit or continue if the response is invalid?
except ValueError:
print("Invalid Input: Make sure your number is greater than zero and no alphabets. Try Again.")
直到“我想再次以”或“我想”的方式回答“程序”之后。若我在这里添加另一个while循环,那个么若用户输入“y”,那个么使用pass语句就可以了。但是当用户回答为“n”时,它不会破坏程序,因为它会让我们进入外循环。
那么如何解决这个问题呢?在