Feb-10-2019, 05:57 PM (This post was last modified: Feb-10-2019, 05:59 PM by missus_brown. Edited 2 times in total.)

I'm super new to Python and I'm really having a hard time with this assignment. The previous assignment was a basic calculator. This assignment builds on that calculator by adding a while loop and adding the option to quit. The calculator is supposed to repeatedly loop back to the beginning and ask for a new character until the user types Q to quit. The first basic calculator was working perfectly, but adding the while statement changed that.

Here's what I've got. It doesn't work right and it doesn't like the break at the bottom. I'm grateful for any guidance.

Here's what I've got. It doesn't work right and it doesn't like the break at the bottom. I'm grateful for any guidance.

print('This program is a basic calculator that allows you to perform calculations using two numbers and a character that indicates which math operation to perform. Options for the characters are + - * / and %.') char = input('Enter a character to indicate which operation to perform or type Q or q to quit: ') #putting this here leaves it out of the while loop, but I can't put it after 'while' because it has to be defined first. while char != 'Q' or 'q': #is it better to start with char == 'q' or 'Q'? Or something entirely diffent? a = float(input('Enter a number: ')) b = float(input('Enter another number: ')) if char == '+': sum = a + b print('The sum of ',a, ' and ', b,' is ', sum , sep = '') elif char == '-': difference = a-b print(a, ' minus ', b, ' equals ', difference, '.', sep = '') elif char == '*': product = a*b print(a, ' times ', b, ' equals ', product, '.', sep='') elif char == '/': if b == 0: print('You can not divide a number by zero.') else: quotient = a/b rounded = format(quotient, '.2f') print(a, ' divided by ', b, ' equals ', rounded, '.', sep = '') elif char == '%': remainder = a%b print('The remainder of ',a, ' and ', b, ' is ', a%b, '.', sep='') else: print('That is not a valid character. Please enter + - * / or %.') else: print('Goodbye') break #this break isn't allowed here because it's after 'else' but I can't figure out where else to put this partThanks in advance for any help!