## Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

### Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.  PLUS

# Why is this an infinite loop (Python)?

This is my second question today. And this one is really making me feel dumb. If someone could look at the code for this calculator in Python, and tell me why it produces an infinite loop (because I can't see why the "goodbye" statement doesn't happen if the func = "X'

I would be grateful. For a bonus, if I could make the string comparison case insensitive, that would make my day BUT really I need to know why this is throwing an infinite loop. Thanks.

```import math

if 0 <= value <= 6.28319:
degrees = value * (180 / math.pi)
elif -6.28319 <= value <= 0:
degrees = value * (180 / math.pi) * -1
elif value > 6.28319:
value = value % 6.28319
degrees = value * (180 / math.pi)
elif value < -6.28319:
value = value % 6.28319
degrees = value * (180 / math.pi)
return degrees

print('This calculator requires you to enter a function and a value.\n')
print('The functions are as follows')
print('S - Sine')
print('C - Cosine')
print('T - Tangent')
print('R - Square Root')
print('N - Natural Log')
print('X - eXit the program')

functionValue = input("Please enter a function and a value: ")
func, value = functionValue.split(' ')
value = float(value)

while func is not 'X':
if func == 'S':
print("The sine of your number is " + str(math.sin(value)))
elif func == 'C':
print("The cosine of your number is " + str(math.cos(value)))
elif func == 'T':
print("The tangent of your number is " + str(math.tan(value)))
elif func == 'R':
print("The square root of your number is " + str(math.sqrt(value)))
elif func == 'L':
print("The natural log of your number is " + str(math.log(value)))
else:

print("Thank you for using the calculator")
print("Press any key to continue")
``` Hi Nancy, Your program is in an infinite loop because the choice to enter a new function and value is Outside of your While loop, so the value that the While loop is evaluating will never change. In regards to your bonus question, one of ways to do a case-insensitive comparison is to simply force an input string to be converted to all upper or lower case.

Here is a working version of your program, though there are still a few kinks to work out if you want to make it non-breakable:

```import math

if 0 <= value <= 6.28319:
degrees = value * (180 / math.pi)
elif -6.28319 <= value <= 0:
degrees = value * (180 / math.pi) * -1
elif value > 6.28319:
value = value % 6.28319
degrees = value * (180 / math.pi)
elif value < -6.28319:
value = value % 6.28319
degrees = value * (180 / math.pi)
return degrees

print('This calculator requires you to enter a function and a value.\n')
print('The functions are as follows')
print('S - Sine')
print('C - Cosine')
print('T - Tangent')
print('R - Square Root')
print('N - Natural Log')
print('X - eXit the program')

func = ''

while func is not 'X':
functionValue = input("Please enter a function and a value: ").upper()
if functionValue == 'X':
print("Thank you for using the calculator")
any_key = input("Press any key to continue")
break

func, value = functionValue.split(' ')
value = float(value)

if func == 'S':
print("The sine of your number is " + str(math.sin(value)))
elif func == 'C':
print("The cosine of your number is " + str(math.cos(value)))
elif func == 'T':
print("The tangent of your number is " + str(math.tan(value)))
elif func == 'R':
print("The square root of your number is " + str(math.sqrt(value)))
elif func == 'L':
print("The natural log of your number is " + str(math.log(value)))
else:
```

If there are any further questions, feel free to ask - and happy coding! Because you only offer the user the ability to give a command and a number once. Meaning that once we start the while-loop it will just keep going.

Add this at the end of you while loop:

```functionValue = input("Please enter a function and a value: ")
```

Also, It doesn't make much sense to having to enter X and a number in order to quit. Just X should be enough.