Your .lower
should be .lower()
. .lower()
is a function, and calling it without parentheses doesn't do anything:
>>> string = 'No'
>>> string.lower
<built-in method lower of str object at 0x1005b2c60>
>>> x = string.lower
>>> x
<built-in method lower of str object at 0x1005b2c60>
>>> x = string.lower()
>>> x
'no'
>>>
Also, you are checking for equality in replay == input(...)
. You just want a single =
to assign:
>>> result = 0
>>> result == 4
False
>>> result = 4
>>> result == 4
True
>>>
You also have an unwanted :
after print replay
in your second while True
loop.
This is a suggestion: instead of using replay in ("no, "n")
, which is very unpythonic, use the built-in method startswith(char)
to see if it starts with that character:
>>> string = "NO"
>>> string.lower().startswith("n")
True
>>> string = "yeS"
>>> string.lower().startswith("y")
True
>>>
This also works for input like naw
, or yeah
, etc.
Here is your edited code:
a = int(input("Enter the first number :"))
b = int(input("Enter the second number :"))
print("sum ---" + str(a+b))
print("difference ---" + str(a-b))
print("product ---" + str(a*b))
print("division ---" + str(a/b))
input()
while True:
print("Do you want to try again?")
while True:
replay = input("Do another Calculation? 'y' for yes. 'n' for no.").lower()
print(replay)
if replay.startswith('y') == True:
break
if replay.startswith('n') == True:
exit()
else:
print("I don't understand what you wrote. Please put in a better answer, such as 'Yes' or 'No'")