QUESTION

# Hey guys , So I'm trying to compile a code that asks for an integer then which operation to use and use said math equation on the number from a range...

Hey guys , So I'm trying to compile a code that asks for an integer then which operation to use and use said math equation on the number from a range of 1 to 10.

Q1 =int(input(" Enter a number 1 or greater: "))

while (Q1 <= 0):

Q1=int(input("  Too small - Try again: "))

if Q1 > 0:

break

print(" Counting from 0 to ",Q1,":",sep="")

for i in range(0,Q1):

print("",i,end=" ")

print()

print()

Q2=input(" Choose math operation (+, -, *): ")

while (Q2 != '+') or (Q2 != '*') or (Q2 != '-'):

Q2 = input("  Invalid input - Try again: ")

if (Q2 == '+') or (Q2 == '*') or (Q2 == '-'):

break

if (Q2 == '+') or (Q2 == '-') or (Q2 == '*'):

for y in range(1,11):

if Q2 == "+":

print(Q1,Q2,y,"=",Q1+y)

elif Q2 == "-":

print(" ",Q1,Q2,y,"=",Q1-y)

else:

print(Q1,Q2,y,"=",Q1*y)

For some reason , When I get to the math operation part , Even if the statement is true on the first Q2 ( + , - or *) It gives me the second attempt then it works from there on. Need some pointers here to improve my overall code and what my mistakes are.

Second question , Can someone explain to me the general idea of ending a while loop that leads to the next algorithm? I tried doing that in my code but I just got even more confused.