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 13, 2020 in Python by anonymous
• 120 points
49,099 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,770 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
13,582 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
7,393 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
80,317 views
0 votes
0 answers

Help, How can I fix this? TypeError: Getting error as __init__() got an unexpected keyword argument 'rotaion_range'.

datagen = ImageDataGenerator(zoom_range=0.2,rotaion_range=10,width_shift_range=0.1, height_shift_range=0.1,horizontal_flip=True, vertical_flip = False ...READ MORE

Oct 20, 2021 in Python by anonymous
• 120 points
603 views
0 votes
0 answers
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
1,910 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
1,207 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,460 points
16,877 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,770 points
8,071 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP