• Register
2 votes
39 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,060 points

Please log in or register to answer this question.

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,950 points

Related questions

0 votes
1 answer 9 views
9 views
Problem: TypeError: ‘float’ object cannot be interpreted as an integer Floating-point numbers are values that can contain a decimal point. Integers are whole numbers. It is common in programming for these two data types to be distinct.How to solve this error
asked Jan 6 Mashhoodch 6.3k points
0 votes
1 answer 20 views
20 views
Problem: Hi there! I am a noob and I have got an assignment in which I have to take two numbers as input from users and print the even numbers that lie between two numbers. I wrote the following program: starting = input("Enter the starting number: ") ending = ... : TypeError: 'str' object cannot be interpreted as an integer I have no idea what is wrong with my program. Can anybody here help me?
asked Dec 21, 2020 Code Learner 5.5k points
1 vote
2 answers 2.3K views
2.3K 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, 2020 Gavin 15.3k points
0 votes
2 answers 1.1K views
1.1K 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
1 vote
1 answer 81 views
81 views
Problem: Here is my sample code below from turtle import * speed(0) hideturtle() c = 450 def grid(x,y,a): seth(0) pu() goto(x,y) pd() for i in range(4): forward(a) rt(90) for i in range(c/10): seth(0) forward(10) rt(90) forward(c) backward(c ... \Desktop\gridv2.py", line 15, in grid for i in range(c/10): TypeError: 'float' object cannot be interpreted as an integer What&rsquo;s wrong with my code?
asked Mar 7, 2020 Gavin 15.3k points
2 votes
1 answer 988 views
988 views
Problem: I am trying a run a program with a simple list object in my code. But it throwing the same error again and again. The error is: list object cannot be interpreted as an integer python. I am attaching my code snippet below: def userNum( ... winsound.PlaySound("SystemExit", winsound.SND_ALIAS) What could be the possible solution for this program? If possible figure the error, please. Thanks
asked Mar 26, 2020 Gavin 15.3k points
1 vote
2 answers 240 views
240 views
Problem: I am begginer in python programming language and I am doing a course in it. I was doing some code to practice python programing. I wrote this code while doing my practice from __future__ import division x = 6.86 y = 9.79 z = 3.03 round((x/y)*0.88*z) But it ... is not callable Is there any problem in my code. I am using python 2.7 as my default python version . I am new so please help me.
asked Apr 4, 2020 LizzyM 6.1k points