What is the error in this python syntax:
x=int(input('Enter the First number - '))
y=int(input('Enter the Second number - '))
z=input('Enter the operator - ')
if (z==+):
print(x+y)
elif(z==-):
print(x-y)
elif(z==*):
print(x*y)
elif(z==/):
print(x/y)
elif(y==0 and z==/):
print('Enter a number other than 0 when using "/" operator')
else:
print('Error')
x=int(input('Enter the First number - '))
y=int(input('Enter the Second number - '))
z=input('Enter the operator - ')
if z==+:
print(x+y)
elif(z==-):
print(x-y)
elif(z==*):
print(x*y)
elif(z==/):
print(x/y)
elif(y==0 and z==/):
print('Enter a number other than 0 when using "/" operator')
else:
print('Error')
Answers
Answer:
x=int(input('Enter the First number - '))
y=int(input('Enter the Second number - '))
z=input('Enter the operator - ')
if (z == '+'):
print(x+y)
elif(z == '-'):
print(x-y)
elif(z == '*'):
print(x*y)
elif(z == '/' and y != 0):
print(x/y)
elif(y == 0):
print('divide by zero!')
else:
print('Error')
Explanation:
Explanation:
What is the error in this python syntax:
x=int(input('Enter the First number - '))
y=int(input('Enter the Second number - '))
z=input('Enter the operator - ')
if (z==+):
print(x+y)
elif(z==-):
print(x-y)
elif(z==*):
print(x*y)
elif(z==/):
print(x/y)
elif(y==0 and z==/):
print('Enter a number other than 0 when using "/" operator')
else:
print('Error')
x=int(input('Enter the First number - '))
y=int(input('Enter the Second number - '))
z=input('Enter the operator - ')
if z==+:
print(x+y)
elif(z==-):
print(x-y)
elif(z==*):
print(x*y)
elif(z==/):
print(x/y)
elif(y==0 and z==/):
print('Enter a number other than 0 when using "/" operator')
else:
print('Error')