Home > Blockchain >  Python | TypeError: unsupported operand type(s) for /: 'NoneType' and 'int' |use
Python | TypeError: unsupported operand type(s) for /: 'NoneType' and 'int' |use

Time:06-21

a = int(float(input("Add : ")))
b =  int(float(input("Add : ")))
c = print(" = " , a**2   b**2)

print(c/2)

I'm going to divide the variable and the number but it happens like this, how do I fix it? | TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'

CodePudding user response:

print returns None, which you assign to c. None can't be divided by an int, hence your error.

If you want to store the result of a**2 b**2 in c, then do so directly:

a = int(input("Add: "))
b = int(input("Add: "))
c = a**2   b**2

print(f"{a=}, {b=}, {c=}")
print(c / 2)

Sample output:

Add: 3
Add: 5
a=3, b=5, c=34
17.0

CodePudding user response:

print is a function which returns None and the side effect of printing its args to stdout. Therefore c has the value None. And None / 2 gives the TypeError

  • Related