Python TypeError: unsupported operand type(s) for ^: 'float' and 'int'

Aris Pap

I wrote a simple program which approximates the evaluation of a definite integral using numerical integration. However, I am stumped when it comes to why I am getting the error in the title. Keep in mind that I haven't touched python in one and a half years so it might be something incredibly obvious that I'm missing, however I'd still be grateful if you could help me :) Here is the code:

import math
def f(x):
    f=math.sqrt(1+(6*x+4)^2)
    return f


lbound=int(input("Input lower bound for the integral"))
ubound=int(input("Input upper bound for the integral"))
n=int(input("Input number of intervals"))
dx=((ubound-lbound)/n)
integral=0
for i in range(1,n):
    integral=integral+dx*f(i*dx)

print (integral)

Here is the full error report IDLE gives me when trying to run the code:

Traceback (most recent call last):
  File "C:\Users\******\Desktop\integrals.py", line 13, in <module>
    integral=integral+dx*f(n*dx)
  File "C:\Users\******\Desktop\integrals.py", line 3, in f
    f=math.sqrt(1+(6*x+4)^2)
TypeError: unsupported operand type(s) for ^: 'float' and 'int'
ilyas patanam

When trying to raise to a power use the operand use ** and not ^.

f=math.sqrt(1+(6*x+4)**2)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

TypeError: unsupported operand type(s) for <<: 'int' and 'float'

From Dev

TypeError: unsupported operand int and NoneType? Python

From Dev

unsupported operand types for * : 'float' and 'decimal'

From Dev

unsupported operand types for //: 'str', 'int'

From Dev

Python TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

From Dev

TypeError: unsupported operand type(s) for +=: 'float' and 'NoneType' in Python 3

From Dev

TypeError: unsupported operand type(s) for -: 'str' and 'int' Python

From Dev

Python 3 TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'

From Dev

Python27 TypeError: unsupported operand for type(s) += 'int' and 'str'

From Dev

TypeError: unsupported operand type in Python

From Dev

TypeError: unsupported operand type(s) for +: 'float' and 'tuple'

From Dev

TypeError: unsupported operand type(s) for +: 'decimal' and 'float'

From Dev

TypeError: unsupported operand type(s) for -: 'float' and 'method'

From Dev

TypeError: unsupported operand type(s) for /: 'float' and 'instancemethod'

From Dev

TypeError: unsupported operand type(s) for -: 'instance' and 'float'

From Dev

TypeError: unsupported operand type(s) for +: 'Timestamp' and 'float'

From Dev

TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

From Dev

TypeError: unsupported operand type(s) for +=: 'int' and 'list'

From Dev

TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

From Dev

TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

From Dev

TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

From Dev

TypeError: unsupported operand type(s) for |: 'int' and 'str'

From Dev

TypeError: unsupported operand type(s) for +: 'int' and 'Element'

From Dev

TypeError: unsupported operand type(s) for //: 'int' and 'graph'

From Dev

TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

From Dev

TypeError For Unsupported Operand type 'int' and 'list'

From Dev

TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

From Dev

TypeError: unsupported operand type(s) for 'Instance' and 'Int'

From Dev

TypeError: unsupported operand type(s) for +=: 'int' and 'str'

Related Related

  1. 1

    TypeError: unsupported operand type(s) for <<: 'int' and 'float'

  2. 2

    TypeError: unsupported operand int and NoneType? Python

  3. 3

    unsupported operand types for * : 'float' and 'decimal'

  4. 4

    unsupported operand types for //: 'str', 'int'

  5. 5

    Python TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

  6. 6

    TypeError: unsupported operand type(s) for +=: 'float' and 'NoneType' in Python 3

  7. 7

    TypeError: unsupported operand type(s) for -: 'str' and 'int' Python

  8. 8

    Python 3 TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'

  9. 9

    Python27 TypeError: unsupported operand for type(s) += 'int' and 'str'

  10. 10

    TypeError: unsupported operand type in Python

  11. 11

    TypeError: unsupported operand type(s) for +: 'float' and 'tuple'

  12. 12

    TypeError: unsupported operand type(s) for +: 'decimal' and 'float'

  13. 13

    TypeError: unsupported operand type(s) for -: 'float' and 'method'

  14. 14

    TypeError: unsupported operand type(s) for /: 'float' and 'instancemethod'

  15. 15

    TypeError: unsupported operand type(s) for -: 'instance' and 'float'

  16. 16

    TypeError: unsupported operand type(s) for +: 'Timestamp' and 'float'

  17. 17

    TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

  18. 18

    TypeError: unsupported operand type(s) for +=: 'int' and 'list'

  19. 19

    TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

  20. 20

    TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

  21. 21

    TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

  22. 22

    TypeError: unsupported operand type(s) for |: 'int' and 'str'

  23. 23

    TypeError: unsupported operand type(s) for +: 'int' and 'Element'

  24. 24

    TypeError: unsupported operand type(s) for //: 'int' and 'graph'

  25. 25

    TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

  26. 26

    TypeError For Unsupported Operand type 'int' and 'list'

  27. 27

    TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

  28. 28

    TypeError: unsupported operand type(s) for 'Instance' and 'Int'

  29. 29

    TypeError: unsupported operand type(s) for +=: 'int' and 'str'

HotTag

Archive