Multiple issues here:
-
assignment from
input
into a variable cannot be checked in while-loop, you should split it into assignment and check. -
else
cannot contain a condition -
you also had a bug in printing the results – you printed
num1
twice -
The indentations are meaningful in Python – please make sure to post it properly indented next time
A fix for the issues above:
def calc():
print('Select operation')
print('Choose from:')
print('+')
print('-')
print('*')
print("https://stackoverflow.com/")
choice=input('Enter choice (+,-,*,/):')
num1=int(input('Enter first number:'))
num2=int(input('Enter second number:'))
if choice == '+':
print("{}+{}={}".format(num1, num2, num1+num2))
elif choice == '-':
print("{}-{}={}".format(num1, num2, num1-num2))
elif choice == '*':
print("{}*{}={}".format(num1, num2, num1*num2))
elif choice == "https://stackoverflow.com/":
print("{}/{}={}".format(num1, num2, num1/num2))
else:
print('Invalid input')
if __name__ == '__main__':
restart="y"
while restart:
if restart == 'y':
print('restart')
calc()
restart = input('Do you want to restart the calculator y/n')
elif restart == 'n':
print('Thanks for using my program')
break
5
solved Why is it saying that the = in bold is an invalid syntax? [duplicate]