TypeError float object cannot be interpreted as an integer

0 votes

Hi Guys, this code give me that type of error how i fix it

from math import exp
y=[((x**4)*(e(-x))) for x in range (1.5,4.5,0.5)]
print(y)

Nov 12, 2020 in Python by anonymous
• 120 points
952 views

1 answer to this question.

0 votes

Hi, @There,

The “TypeError: ‘float’ object cannot be interpreted as an integer” error is raised when you try to use a floating-point number in a place where only an integer is accepted.

This error is common when you try to use a floating-point number in a range() statement. 

The range function does not work with floats. Only integer values can be specified as the start, stop, and step arguments. But you can use this in a different way. I have attached one example for your reference.

def range_with_floats(start, stop, step):
    while stop > start:
        yield start
        start += step
for i in range_with_floats(0.1, 0.5, 0.1):
    print(i)

I hope this will help you.

answered Nov 13, 2020 by Gitika
• 65,870 points

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

Error saying "TypeError: descriptor object needs an argument"

The error is pretty straight forward, toy ...READ MORE

answered May 28, 2019 in Python by Alisha
5,977 views
+1 vote
0 answers

TypeError: only integer scalar arrays can be converted to a scalar index

import cv2 import numpy as np import matplotlib.pyplot as ...READ MORE

Dec 18, 2019 in Python by sandeep
• 130 points
6,360 views
0 votes
1 answer

TypeError: cannot unpack non-iterable NoneType object

Hello, The “TypeError: cannot unpack non-iterable NoneType object” ...READ MORE

answered Oct 5, 2020 in Python by Lisa
24,722 views
0 votes
1 answer

Python class inherits an object

Python 3.x: class MyClass(object): = new-style class class MyClass: ...READ MORE

answered Apr 17, 2018 in Python by anonymous
723 views
0 votes
1 answer

Size of an object in Python

Use sys.getsizeof() function: >>> import sys >>> s = ...READ MORE

answered May 25, 2018 in Python by Nietzsche's daemon
• 4,260 points
394 views
+1 vote
1 answer

How to append an integer to a string?

You can not directly concatenate two different ...READ MORE

answered Aug 16, 2018 in Python by Omkar
• 69,130 points
521 views
0 votes
1 answer

'python' is not recognized as an internal or external command

I have met same issue when I ...READ MORE

answered Aug 24, 2018 in Python by Priyaj
• 58,120 points
413 views
0 votes
2 answers

TypeError: 'float' object cannot be interpreted as an integer

Hi@akhtar, The range function does not work with ...READ MORE

answered Jun 29, 2020 in Python by MD
• 95,180 points
9,976 views
0 votes
1 answer

TypeError: 'Element' object is not subscriptable

Hey Bharti, You can get some idea from ...READ MORE

answered Feb 18, 2020 in Python by Gitika
• 65,870 points
4,409 views