# I have a error

+10 votes
asked Nov 8, 2022
When I add in this code it does not add

https://onlinegdb.com/kPlY2pxY8

## 4 Answers

0 votes
answered Nov 9, 2022 by (66,630 points)

Try/except can be used for catching exceptions:

```print ('Type in 2 numbers and then choose to add, subtract or multiply them')
try:
num1 = int(input("Type in the first number: "))
except ValueError:
print('This code needs a number and not a alphabet')
num1 = 1

try:
num2 = int(input("Type in the second number: "))
except ValueError:
print('This code needs a number and not a alphabet')
num2 = 1

chose = input('Type in a addition, subtraction or multiplication sign: ')
if chose == '+':
print(num1 + num2)
elif chose == '-':
print(f"{num1} - {num2} = ", num1 - num2)
elif chose == '*':
print (num1 * num2)
else:
print('The sign you have chosen is not one of the choices'```
0 votes
answered Nov 15, 2022 by (140 points)
#check this code

a = 0
print ('Type in 2 numbers and then choose to add, subtract or multiply them')

num = int(input("Type in the first number: "))
if num != int:
print('This code needs a number and not a alphabet')
a = 1

number = int(input("Type in the second number: "))
if number != int:
print('This code needs a number and not a alphabet')
a = 1

chose = input('Type in a addition, subtraction or multiplication sign: ')
if chose == '+':
print(num + number)
elif chose == '-':
print(num - number)
elif chose == '*':
print (num * number)
else:
print('The sign you have chosen is not one of the choices')
a = 1
+2 votes
answered Nov 17, 2022 by (180 points)
Line 13 and Line 18

Replace variable_name with your respective variable names

if type(variable_name) != int: or if not isinstance(variable_name, int):
0 votes
answered Nov 25, 2022 by (260 points)