I'm trying to solve FizzBuzz using a recursive function (but this isn't what I'm having a problem with yet). I have an if statement that checks if the user typed 'Y' or 'y', but it still runs even if the condition is true and I can't figure out why. I feel like pulling my hair out. The problem is at exit_check.
import sys
final = []
def fizzbuzz(n):
if n % 5 == 0 and n % 3 == 0:
print('Append: FizzBuzz')
final.append('FizzBuzz')
elif n % 3 == 0:
print('Append: Fizz')
final.append('Fizz')
elif n % 5 == 0:
print('Append: Buzz')
final.append('Buzz')
else:
print('Append: ' + str(n))
final.append(n)
exit_check = input('Exit check: ')
if exit_check == 'y' or 'Y':
print('Why does this still get called with the wrong variable?: ' + exit_check)
sys.exit()
if n > 0:
fizzbuzz(n - 1)
print(final)
fizzbuzz(10)