• Register
1 vote
94 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)
    for i in range(c/10):
        seth(0)
        rt(90)
        forward(10)
        rt(90)
        forward(c)
        backward(c)
    pu()
    goto(a+10,0)
    write("x")
    goto(0,a+10)
    write("y")
    pd()

grid(0,0,c)
grid(-c,0,c)
grid(-c,c,c)
grid(0,c,c)

 

And I am getting this error message

Traceback (most recent call last):
  File "C:\Users\nick\Desktop\gridv2.py", line 35, in <module>
    grid(0,0,c)
  File "C:\Users\nick\Desktop\gridv2.py", line 15, in grid
    for i in range(c/10):
TypeError: 'float' object cannot be interpreted as an integer

What’s wrong with my code?

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote
 
Best answer

Solution:

Here, c/10 is a float number because / always returns a float number.

Make the value an integer again:

for i in range(int(c / 10)):

You may also (//) the floor division operator to make it an integer number.

for i in range(c // 10):

 

13 9 6
94,240 points

Related questions

0 votes
1 answer 40 views
40 views
Problem: TypeError: &lsquo;float&rsquo; 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 13k points
2 votes
1 answer 61 views
61 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 ... 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?
asked Mar 23, 2020 LizzyM 6.1k points
0 votes
1 answer 78 views
78 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 9.2k points
0 votes
1 answer 174 views
0 votes
1 answer 17 views
17 views
typeerror: 'float' object cannot be interpreted as an integer
asked Feb 16 ArifulIslam 7.5k points
0 votes
1 answer 9 views
9 views
Problem: Why this message keep shown to me :deprecationwarning: object of type <class 'float'> cannot be safely interpreted as an integer.
asked Mar 15 Wafa Abu Yousef 6.1k points
0 votes
2 answers 1.3K views
1.3K 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
0 votes
1 answer 14 views
14 views
Problem: What could be the possible solution for this program? If possible figure the error, please: list object cannot be interpreted as an integer python .
asked Mar 14 Wafa Abu Yousef 6.1k points