I do not know what to do, I’m making a table of results for an exercise and says that is giving error in line 4

Asked

Viewed 28 times

-3

a = input ('Primeiro número: ') 
b = input ('Segundo número: ')
c = a+b
d = a-b
e = a*b
f = a**b
g = a//b
h = a%b

print('a = ' , a , '\nb = ' , b , '\na + b = ', c , '\na - b = ', d , '\na * b = ', e , '\na ** b = ', f , '\na // b = ', g , '\na % b = ' , h)

When I run and put the two numbers, it appears to this:

Traceback (Most recent call last):

File "C:/Users/SONY/Desktop/Python/lesson 1.py", line 4, in d = a-b

Typeerror: Unsupported operand type(s) for -: 'str' and 'str'

1 answer

-1


You need to convert the input to some numeric type. Because the default is to return string

# a função float abaixo faz a conversão de tipos
a = float(input ('Primeiro número: '))
b = float(input ('Segundo número: '))
c = a+b
d = a-b
e = a*b
f = a**b
g = a//b
h = a%b

print('a = ' , a , '\nb = ' , b , '\na + b = ', c , '\na - b = ', d , '\na * b = ', e , '\na ** b = ', f , '\na // b = ', g , '\na % b = ' , h)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.