0

Hello I am very new to code and I need to know how to output the value obtained by calculating |x+y| where x is a floating point and y is an integer, both unknown inputs. I have tried many things and cannot succeed please help me.

This is what I have now but I know it is very wrong :( In most cases when trying things I get the error TypeError: unsupported operand type(s) for +: 'int' and 'str' This was my most recent attempt:

x = int(input())

y = input()

w = (x + y)

print (abs(w))
niraj
  • 17,498
  • 4
  • 33
  • 48
MollyV
  • 55
  • 2
  • 3

1 Answers1

2

You need to convert y to float:

x = int(input())
y = float(input())
w = (x + y)
print(abs(w))

The function input returns a string, from the documentation:

If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string

Dani Mesejo
  • 61,499
  • 6
  • 49
  • 76