Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7875875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:04:26+00:00 2026-06-03T03:04:26+00:00

def __init__(self, maximum, start=0, step=1): Sets the maximum, start, and step try: self.maximum =

  • 0
def __init__(self, maximum, start=0, step=1):
        """Sets the maximum, start, and step"""
        try:
            self.maximum = math.ceil(maximum)
            self.start = math.ceil(start)
            self.step = math.ceil(step)
        except TypeError:
            return "Error, attributes must be of type int or float"
    def __iter__(self):
        """Iterates over the range"""
        return iter(range(self.start, self.maximum, self.step))

is the relevant code. Whenever I call, say:

j = crange.ChangeableRange(4)
list(j)

I get the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "crange.py", line 16, in __iter__
    return iter(range(self.start, self.maximum, self.step))
TypeError: 'str' object cannot be interpreted as an integer

Why? How do I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:04:27+00:00Added an answer on June 3, 2026 at 3:04 am

    The range function expects integers for arguments. It looks like you’ve created a string for either start, maximum, or step with something like self.maximum = int(math.ceil(maximum)).

    Also note that in Python 2, the math.ceil function returns a float value, so those would need to be converted to integers.

    In Python 3, your code works fine:

    >>> import math
    >>> class ChangeableRange:
            def __init__(self, maximum, start=0, step=1):
                """Sets the maximum, start, and step"""
                try:
                    self.maximum = math.ceil(maximum)
                    self.start = math.ceil(start)
                    self.step = math.ceil(step)
                except TypeError:
                    return "Error, attributes must be of type int or float"
            def __iter__(self):
                """Iterates over the range"""
                return iter(range(self.start, self.maximum, self.step))
    
    
    >>> j = ChangeableRange(4)
    >>> print(list(j)) 
    [0, 1, 2, 3]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class A(): def __init__(self): self.__var = 5 def get_var(self): return self.__var def set_var(self, value):
class MyClass(object): def __init__(self): self._my_secret_thing = 1 def _i_get(self): return self._my_secret_thing def _i_set(self, value):
def makecounter(): return collections.defaultdict(int) class RankedIndex(object): def __init__(self): self._inverted_index = collections.defaultdict(list) self._documents = []
import math class Point: def __init__(self,x,y): self.x = x self.y = y def move(self,x,y):
class Books(): def __init__(self): self.__dict__['referTable'] = 1 @property def referTable(self): return 2 book =
class A(): def __init__(self, data=''): self.data = data def __str__(self): return str(self.data) d =
class Square: def __init__(self,start,stop): self.value = start - 1 self.stop = stop def __iter__(self):
class x: def __init__(self,name): self.name=name def __str__(self): return self.name def __cmp__(self,other): print(cmp method called
class Foo(object): def __init__(self,x): self.x = x self.is_bar = False def __repr__(self): return str(self.x)
class a(object): def __init__(self): self.b = 1 self.c = 2 This gives the error:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.