You are creating a situation where the while loop exit condition is always True. Test this ...
overwrite = None
while overwrite != 'y' or overwrite != 'n':
overwrite = raw_input("Do you want to overwrite (Y/N)? ").lower()
print overwrite != 'y'
print overwrite != 'n'
# overall condition
print False or True
Easier to understand is this approach ...
while True:
overwrite = raw_input("Do you want to overwrite (Y/N)? ").lower()
if overwrite == 'y' or overwrite == 'n':
break
... or even simpler ...
while True:
overwrite = raw_input("Do you want to overwrite (Y/N)? ").lower()
if overwrite in 'yn':
break
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
For future coding conundrums, an "or" can be viewed as an if / elif, and "and" can be viewed as two nested if statements, which you would adapt to while() statements.
while overwrite != 'Y'.lower() or overwrite != 'N'.lower(): becomes
if overwrite != 'Y'.lower():
do something
elif overwrite != 'N'.lower():
do the same thing
For completeness, the 'and' would be
if overwrite != 'Y'.lower() and overwrite != 'N'.lower(): becomes
if overwrite != 'Y'.lower():
if overwrite != 'N'.lower():
do something
Hopefully this will help sort out the and/or's in the future.
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
What woooee said was correct:
overwrite=""
while(overwrite!="Y".lower() and overwrite!="N".lower()):
overwrite=raw_input()
Here "Y".lower() does not make any sense since it is simply 'y'
sneekula
Nearly a Posting Maven
2,427 posts since Oct 2006
Reputation Points: 961
Solved Threads: 212