I have been trying to make a logarithm calculator on Python. I am just one step away from finishing it. Here is the code:
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.")
After the else statement, I want the program to ask the user to respond again and again until it is a valid response as "y" or "Y" and "n" or "N". If I add another while loop here, it would work good to with pass statement if user enters "y". But it won't break the program when the user responds as "n" since it would land us in the outer loop. So how to sort this out?
response == ("y" or "Y")doesn't look right. You wantresponse in 'Yy'.