• Register
2 votes
34 views

Problem:

I am a python newbee. I was trying some code :
x = int(input("Input an Integer:"))
  res = [x]
    while x != 1:
  --->   for i in range(2, a):
            if x % i == 0:
                res.append(i)
                x = x / i
                break
    print(res)

 

but this code shows some error message and it did not compile. The error message is :

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

 Can any one tell me why am I getting this kind of error message?

10 7 2
6,050 points

1 Answer

0 votes

Answer:

In your program you should write:

x = x // i

Instead of:

x = x / i

And you should not put x on your list

So your code should be like

x = int(input("Input an Integer:"))
  res = []
    while x != 1:
  --->   for i in range(2, a):
            if x % i == 0:
                res.append(i)
                x = x // i
                break
    print(res)

Let me know if this helps you or not, Happy Coding.

11 6 4
34,930 points

Related questions

1 vote
2 answers 1.6K views
1.6K views
Problem: Hello, I am not extremely versed in numpy, so I am not exactly sure what I am doing wrong. I got it to work with made-up data but I am not sure as to what it is not working with the data I put in. All I am trying to do is fit the data ... plt.ylabel('T') plt.legend() plt.show() The error I am getting is following below TypeError: 'numpy.float64' object cannot be interpreted as an integer
asked Mar 9 Gavin 15.3k points
0 votes
2 answers 792 views
792 views
Problem : I am facing following type error while trying to execute the Python program deprecationwarning: object of type <class 'float'> cannot be safely interpreted as an integer.
asked Nov 14, 2019 peterlaw 6.9k points