Datasets:

inputs
stringlengths
50
14k
targets
stringlengths
4
655k
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed # ^_^ def bark(self): return 'Woof' snoopy = Dog("Beagle") scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): bark = None def __init__(self, breed): self.breed = breed @property def bark(self): return Dog.bark @bark.setter def bark(self, func): Dog.bark = func snoopy = Dog("Beagle") snoopy.bark = lambda x: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog: def __init__(self, breed): self.breed = breed def bark(self): return "Woof" class Snoopy(Dog): def __init__(self, breed): Dog.__init__(self, breed) def bark(self): return self.bark class Scooby(Dog): def __init__(self, breed): Dog.__init__(self, breed) def bark(self): pass #super(Dog, self).bark() snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed snoopy = Dog("Woof") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Woof") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, bark): self.bark = "Woof" snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed # def bark(): # return 'Woof' snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed,bark): self.breed = breed self.bark = bark snoopy = Dog("Beagle",'Woof') snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane",'Woof') scoobydoo.bark = lambda : 'Woof'
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed:str): self.breed = breed def bark(self) ->str: return "Woof" snoopy = Dog("Beagle") scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed, bark): self.breed = breed def __init__(self, bark): self.bark = bark snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof" scoobydoo.platz = lambda: "Platz"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self): return self.breed snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Woof")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(): return self.breed snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed, sound): self.breed = breed self.sound = sound def bark(self): return self.sound snoopy = Dog("Beagle", "Woof") scoobydoo = Dog("Great Dane", "Woof")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def breed(self): return self.breed snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda:"Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(woof): return "Woof" snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(cls): return "Woof" snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class BigDog (): def __init__(self, breed): self.breed = breed class Dog (BigDog): @staticmethod def bark(): return "Woof" snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self): return "Woof" # Instantiate two Dog Objects snoopy = Dog("Beagle") scoobydoo = Dog("Great Dane") # Call bark() method snoopy.bark() scoobydoo.bark()
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" Dog.bark = staticmethod(snoopy.bark) scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark (self): s='' for i in self.breed: s = 'Woof' return s snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed snoopy = Dog("Beagle") scoobydoo = Dog("Great Dane") scoobydoo.bark = snoopy.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self): if self.breed == 'Beagle' or self.breed == "Great Dane": return "Woof" else: return "undefined" snoopy = Dog("Beagle") scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self): return self snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): _bark = "Woof" def __init__(self, breed): self.breed = breed def bark(cls): return cls._bark snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Beagle") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed self.bark = lambda: "Woof" snoopy = Dog("Husky") scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self, breed =''): return 'Woof' snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed self.bark = lambda: "Woof" snoopy = Dog("Beagle") scoobydoo = Dog("Great Dane") scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self, bark): self.bark = bark snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof" #Not hard at all
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
# dog the class class Dog (): # setting self to breed def __init__(self, breed): self.breed = breed self.bark = lambda: "Woof" snoopy = Dog("Beagle") scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self): return "Woof" snoopy = Dog("Beagle") snoopy.bark() scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed @classmethod def bark(self): return "Woof" snoopy = Dog("Beagle") scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(inp): return "Woof" snoopy = Dog("Beagle") scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog(object): def __init__(self, breed): self.breed = breed def bark(self): return 'Woof' snoopy, scoobydoo = Dog("Beagle"), Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, bark): self.bark = bark snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self): bark = 'Woof' self.bark = bark snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self): return lambda: "Woof" snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(s): return 'Woof' snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" class Dog(Dog): def bark(self): return "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed self.message = "Woof" def bark(self): return self.message snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed snoopy = Dog("Beagle") scoobydoo = Dog("Great Dane") snoopy.bark = lambda: "Woof" scoobydoo.bark = lambda: "Woof" snoopy.bark() scoobydoo.bark()
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
""" The instructions say to use method prototypes which don't exist in Python. Instead, we could monkey patch the internal __dict__ of the parent class, like the example in [1], but this isn't very Pythonic, so I've subclassed instead. [1]: http://stackoverflow.com/a/33033631/149428 """ class Dog(object): def __init__(self, breed): self.breed = breed class BarkingDog(Dog): def bark(self): return 'Woof' snoopy = BarkingDog('Beagle') scoobydoo = BarkingDog('Great Dane')
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed, sound): self.breed = breed self.bark = sound def sound(): return 'Woof' snoopy = Dog("Beagle", sound) scoobydoo = Dog("Great Dane", sound)
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed snoopy = Dog("Beagle") Dog.bark = lambda x: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self): return "".join('Woof') snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(*sound): return "Woof" snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(): return "Woof" snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(arg): return "Woof" snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self): return "Woof" snoopy = Dog("Beagle") #snoopy.bark #= lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self): return "Woof" snoopy = Dog("Beagle") # snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") snoopy.bark() scoobydoo.bark()
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self): return 'Woof' snoopy = Dog('snoopy') scoobydoo = Dog('scoobydoo')
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") #Just using lambda to make a mini function scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(name): return "Woof" snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed self.bark def bark(self): return "Woof" snoopy = Dog("Beagle") scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self, bak = "Woof"): self.bak = bak snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(n): return "Woof" snoopy = Dog("Beagle") scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed, sound="Woof"): self.breed = breed self.sound = sound def bark(self): return self.sound snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(sound): print(sound) snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed def bark(self, woof): print("Woof") snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda:"Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog(object): def bark(self): return "Woof" #Dog.bark = bark def __init__(self, breed): self.breed = breed #Dog.bark = bark snoopy = Dog("Beagle") scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = Dog = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): bark = "Woof" def __init__(self, breed): self.breed = breed def bark(self): return "Woof" snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog: def __init__(self, name): pass def bark(self): return 'Woof' snoopy = Dog("Beagle") scoobydoo = Dog("Great Dane")
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): def __init__(self, breed): self.breed = breed self.bark = "Woof" snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof"
Teach snoopy and scooby doo how to bark using object methods. Currently only snoopy can bark and not scooby doo. ```python snoopy.bark() #return "Woof" scoobydoo.bark() #undefined ``` Use method prototypes to enable all Dogs to bark.
class Dog (): bark = "" def __init__(self, breed): self.breed = breed snoopy = Dog("Beagle") snoopy.bark = lambda: "Woof" scoobydoo = Dog("Great Dane") scoobydoo.bark = lambda: "Woof"
Complete the solution so that it returns a formatted string. The return value should equal "Value is VALUE" where value is a 5 digit padded number. Example: ```python solution(5) # should return "Value is 00005" ```
def solution(value): return "Value is %05d" % value
Complete the solution so that it returns a formatted string. The return value should equal "Value is VALUE" where value is a 5 digit padded number. Example: ```python solution(5) # should return "Value is 00005" ```
solution='Value is {:05d}'.format
Complete the solution so that it returns a formatted string. The return value should equal "Value is VALUE" where value is a 5 digit padded number. Example: ```python solution(5) # should return "Value is 00005" ```
def solution(value): num = 5 - len(str(value)) zeros = "" for i in range(num): zeros += "0" return("Value is {}".format(zeros + str(value)))
Complete the solution so that it returns a formatted string. The return value should equal "Value is VALUE" where value is a 5 digit padded number. Example: ```python solution(5) # should return "Value is 00005" ```
def solution(value): return f'Value is {value:05d}'
Complete the solution so that it returns a formatted string. The return value should equal "Value is VALUE" where value is a 5 digit padded number. Example: ```python solution(5) # should return "Value is 00005" ```
def solution(value): return f'Value is {value:05}'
Complete the solution so that it returns a formatted string. The return value should equal "Value is VALUE" where value is a 5 digit padded number. Example: ```python solution(5) # should return "Value is 00005" ```
def solution(value): return 'Value is {}'.format(str(value).zfill(5)) return 'Value is {:>5}'.format(value)
Complete the solution so that it returns a formatted string. The return value should equal "Value is VALUE" where value is a 5 digit padded number. Example: ```python solution(5) # should return "Value is 00005" ```
solution= "Value is {:05}".format
Complete the solution so that it returns a formatted string. The return value should equal "Value is VALUE" where value is a 5 digit padded number. Example: ```python solution(5) # should return "Value is 00005" ```
solution = lambda q: 'Value is %05d' % q
Complete the solution so that it returns a formatted string. The return value should equal "Value is VALUE" where value is a 5 digit padded number. Example: ```python solution(5) # should return "Value is 00005" ```
def solution(value): return f'Value is {value:0>5}'
Complete the solution so that it returns a formatted string. The return value should equal "Value is VALUE" where value is a 5 digit padded number. Example: ```python solution(5) # should return "Value is 00005" ```
def solution(value): padded = str(value).zfill(5) return 'Value is ' + padded
There are a **n** balls numbered from 0 to **n-1** (0,1,2,3,etc). Most of them have the same weight, but one is heavier. Your task is to find it. Your function will receive two arguments - a `scales` object, and a ball count. The `scales` object has only one method: ```python get_weight(left, right) ``` where `left` and `right` are arrays of numbers of balls to put on left and right pan respectively. If the method returns `-1` - left pan is heavier If the method returns `1` - right pan is heavier If the method returns `0` - both pans weigh the same So what makes this the "ubermaster" version of this kata? First, it's not restricted to 8 balls as in the previous versions - your solution has to work for 8-500 balls. Second, you can't use the scale any more than mathematically necessary. Here's a chart: ball count | uses ----------------- 0-9 | 2 10-27 | 3 28-81 | 4 82-243 | 5 244-500 | 6 Too hard? Try lower levels by [tiriana](http://www.codewars.com/users/tiriana): * [novice](http://www.codewars.com/kata/544047f0cf362503e000036e) * [conqueror](http://www.codewars.com/kata/54404a06cf36258b08000364) * [master](http://www.codewars.com/kata/find-heavy-ball-level-master)
def find_ball(scales, n): select = list(range(n)) while len(select) > 1: left, right, unused = select[::3], select[1::3], select[2::3] if len(select) % 3 == 1: unused.append(left.pop()) select = [left, unused, right][scales.get_weight(left, right) + 1] return select.pop()
There are a **n** balls numbered from 0 to **n-1** (0,1,2,3,etc). Most of them have the same weight, but one is heavier. Your task is to find it. Your function will receive two arguments - a `scales` object, and a ball count. The `scales` object has only one method: ```python get_weight(left, right) ``` where `left` and `right` are arrays of numbers of balls to put on left and right pan respectively. If the method returns `-1` - left pan is heavier If the method returns `1` - right pan is heavier If the method returns `0` - both pans weigh the same So what makes this the "ubermaster" version of this kata? First, it's not restricted to 8 balls as in the previous versions - your solution has to work for 8-500 balls. Second, you can't use the scale any more than mathematically necessary. Here's a chart: ball count | uses ----------------- 0-9 | 2 10-27 | 3 28-81 | 4 82-243 | 5 244-500 | 6 Too hard? Try lower levels by [tiriana](http://www.codewars.com/users/tiriana): * [novice](http://www.codewars.com/kata/544047f0cf362503e000036e) * [conqueror](http://www.codewars.com/kata/54404a06cf36258b08000364) * [master](http://www.codewars.com/kata/find-heavy-ball-level-master)
def find_ball(scales, ball_count): balls = range(ball_count) while (len(balls) > 1): x = len(balls) / 3 + (len(balls) % 3 > 0) j, k, l = balls[:x], balls[x:x*2], balls[x*2:] balls = [l, k, j][scales.get_weight(j, k)] return balls[0]
There are a **n** balls numbered from 0 to **n-1** (0,1,2,3,etc). Most of them have the same weight, but one is heavier. Your task is to find it. Your function will receive two arguments - a `scales` object, and a ball count. The `scales` object has only one method: ```python get_weight(left, right) ``` where `left` and `right` are arrays of numbers of balls to put on left and right pan respectively. If the method returns `-1` - left pan is heavier If the method returns `1` - right pan is heavier If the method returns `0` - both pans weigh the same So what makes this the "ubermaster" version of this kata? First, it's not restricted to 8 balls as in the previous versions - your solution has to work for 8-500 balls. Second, you can't use the scale any more than mathematically necessary. Here's a chart: ball count | uses ----------------- 0-9 | 2 10-27 | 3 28-81 | 4 82-243 | 5 244-500 | 6 Too hard? Try lower levels by [tiriana](http://www.codewars.com/users/tiriana): * [novice](http://www.codewars.com/kata/544047f0cf362503e000036e) * [conqueror](http://www.codewars.com/kata/54404a06cf36258b08000364) * [master](http://www.codewars.com/kata/find-heavy-ball-level-master)
from math import ceil def find_ball(scales, n): li = list(range(n)) while len(li)!=1: d = ceil(len(li) / 3) who = scales.get_weight(li[:d], li[-d:]) li = [li[d:-d], li[-d:], li[:d]][who] return li[0]
There are a **n** balls numbered from 0 to **n-1** (0,1,2,3,etc). Most of them have the same weight, but one is heavier. Your task is to find it. Your function will receive two arguments - a `scales` object, and a ball count. The `scales` object has only one method: ```python get_weight(left, right) ``` where `left` and `right` are arrays of numbers of balls to put on left and right pan respectively. If the method returns `-1` - left pan is heavier If the method returns `1` - right pan is heavier If the method returns `0` - both pans weigh the same So what makes this the "ubermaster" version of this kata? First, it's not restricted to 8 balls as in the previous versions - your solution has to work for 8-500 balls. Second, you can't use the scale any more than mathematically necessary. Here's a chart: ball count | uses ----------------- 0-9 | 2 10-27 | 3 28-81 | 4 82-243 | 5 244-500 | 6 Too hard? Try lower levels by [tiriana](http://www.codewars.com/users/tiriana): * [novice](http://www.codewars.com/kata/544047f0cf362503e000036e) * [conqueror](http://www.codewars.com/kata/54404a06cf36258b08000364) * [master](http://www.codewars.com/kata/find-heavy-ball-level-master)
def find_ball(scales, ball_count): def find_number(numbers): length = len(numbers) if length == 1: return numbers[0] n = length // 3 + (length % 3 == 2) left, right, remaining = numbers[:n], numbers[n:(2 * n)], numbers[(2 * n):] result = scales.get_weight(left, right) if result < 0: return find_number(left) elif result > 0: return find_number(right) else: return find_number(remaining) return find_number(list(range(ball_count)))
There are a **n** balls numbered from 0 to **n-1** (0,1,2,3,etc). Most of them have the same weight, but one is heavier. Your task is to find it. Your function will receive two arguments - a `scales` object, and a ball count. The `scales` object has only one method: ```python get_weight(left, right) ``` where `left` and `right` are arrays of numbers of balls to put on left and right pan respectively. If the method returns `-1` - left pan is heavier If the method returns `1` - right pan is heavier If the method returns `0` - both pans weigh the same So what makes this the "ubermaster" version of this kata? First, it's not restricted to 8 balls as in the previous versions - your solution has to work for 8-500 balls. Second, you can't use the scale any more than mathematically necessary. Here's a chart: ball count | uses ----------------- 0-9 | 2 10-27 | 3 28-81 | 4 82-243 | 5 244-500 | 6 Too hard? Try lower levels by [tiriana](http://www.codewars.com/users/tiriana): * [novice](http://www.codewars.com/kata/544047f0cf362503e000036e) * [conqueror](http://www.codewars.com/kata/54404a06cf36258b08000364) * [master](http://www.codewars.com/kata/find-heavy-ball-level-master)
import math def find_ball(scales, lRange): if type(lRange)==int : lRange = range(lRange) if len(lRange)==1 : return lRange[0] slice = int(math.ceil(len(lRange)/3.0)) res = scales.get_weight(lRange[:slice],lRange[slice:slice*2]) if res == -1: return find_ball(scales, lRange[:slice]) elif res == 1: return find_ball(scales, lRange[slice:slice*2]) else: return find_ball(scales, lRange[slice*2:])
There are a **n** balls numbered from 0 to **n-1** (0,1,2,3,etc). Most of them have the same weight, but one is heavier. Your task is to find it. Your function will receive two arguments - a `scales` object, and a ball count. The `scales` object has only one method: ```python get_weight(left, right) ``` where `left` and `right` are arrays of numbers of balls to put on left and right pan respectively. If the method returns `-1` - left pan is heavier If the method returns `1` - right pan is heavier If the method returns `0` - both pans weigh the same So what makes this the "ubermaster" version of this kata? First, it's not restricted to 8 balls as in the previous versions - your solution has to work for 8-500 balls. Second, you can't use the scale any more than mathematically necessary. Here's a chart: ball count | uses ----------------- 0-9 | 2 10-27 | 3 28-81 | 4 82-243 | 5 244-500 | 6 Too hard? Try lower levels by [tiriana](http://www.codewars.com/users/tiriana): * [novice](http://www.codewars.com/kata/544047f0cf362503e000036e) * [conqueror](http://www.codewars.com/kata/54404a06cf36258b08000364) * [master](http://www.codewars.com/kata/find-heavy-ball-level-master)
import math as m def find_baller(s, r): count = len(r) if count == 1: return r[0] size = 3**(m.ceil(m.log(count,3))-1) x = size if size > count-size: x -= 2*size-count parts = [r[:x] , r[x:-x], r[-x:]] x = s.get_weight(parts[0], parts[2])+1 print(x) return find_baller(s,parts[x]) def find_ball(s,count): return find_baller(s,list(range(count)))
There are a **n** balls numbered from 0 to **n-1** (0,1,2,3,etc). Most of them have the same weight, but one is heavier. Your task is to find it. Your function will receive two arguments - a `scales` object, and a ball count. The `scales` object has only one method: ```python get_weight(left, right) ``` where `left` and `right` are arrays of numbers of balls to put on left and right pan respectively. If the method returns `-1` - left pan is heavier If the method returns `1` - right pan is heavier If the method returns `0` - both pans weigh the same So what makes this the "ubermaster" version of this kata? First, it's not restricted to 8 balls as in the previous versions - your solution has to work for 8-500 balls. Second, you can't use the scale any more than mathematically necessary. Here's a chart: ball count | uses ----------------- 0-9 | 2 10-27 | 3 28-81 | 4 82-243 | 5 244-500 | 6 Too hard? Try lower levels by [tiriana](http://www.codewars.com/users/tiriana): * [novice](http://www.codewars.com/kata/544047f0cf362503e000036e) * [conqueror](http://www.codewars.com/kata/54404a06cf36258b08000364) * [master](http://www.codewars.com/kata/find-heavy-ball-level-master)
from math import log def find_ball(scales, ball_count): count=2 if ball_count <=9 else int(log(ball_count, 3))+1 if str(log(ball_count, 3))[-2:]!=".0" else int(log(ball_count, 3)) res=[i for i in range(ball_count)] for i in range(count): if len(res)<=2: break flag=scales.get_weight(res[:(len(res)+1)//3], res[(len(res))-(len(res)+1)//3:]) if flag==-1: res=res[:(len(res)+1)//3] elif flag==1: res=res[(len(res))-(len(res)+1)//3:] elif flag==0: res=res[(len(res)+1)//3:(len(res))-(len(res)+1)//3] if len(res)==1: return res[0] return res[0] if scales.get_weight(res[:1], res[1:])==-1 else res[1]
There are a **n** balls numbered from 0 to **n-1** (0,1,2,3,etc). Most of them have the same weight, but one is heavier. Your task is to find it. Your function will receive two arguments - a `scales` object, and a ball count. The `scales` object has only one method: ```python get_weight(left, right) ``` where `left` and `right` are arrays of numbers of balls to put on left and right pan respectively. If the method returns `-1` - left pan is heavier If the method returns `1` - right pan is heavier If the method returns `0` - both pans weigh the same So what makes this the "ubermaster" version of this kata? First, it's not restricted to 8 balls as in the previous versions - your solution has to work for 8-500 balls. Second, you can't use the scale any more than mathematically necessary. Here's a chart: ball count | uses ----------------- 0-9 | 2 10-27 | 3 28-81 | 4 82-243 | 5 244-500 | 6 Too hard? Try lower levels by [tiriana](http://www.codewars.com/users/tiriana): * [novice](http://www.codewars.com/kata/544047f0cf362503e000036e) * [conqueror](http://www.codewars.com/kata/54404a06cf36258b08000364) * [master](http://www.codewars.com/kata/find-heavy-ball-level-master)
def split(scales,next): if len(next)==1: return next[0] elif len(next) ==2: w = scales.get_weight([next[0]],[next[1]]) if w==1: return next[1] else: return next[0] elif len(next)==3: w = scales.get_weight([next[0]],[next[1]]) if w==0: return next[2] elif w==-1: return next[0] else: return next[1] lock_size = (len(next)+1)//3 l =next[:lock_size] r = next[lock_size:lock_size+ lock_size] f = next[lock_size+ lock_size:] return find(scales,f,l,r) def find(scales,free,first,second): w = scales.get_weight(first,second) if w ==0: return split(scales,free) elif w==-1: return split(scales,first) elif w==1: return split(scales,second) def find_ball(scales, ball_count): next = list(range(ball_count)) return split(scales,next)
There are a **n** balls numbered from 0 to **n-1** (0,1,2,3,etc). Most of them have the same weight, but one is heavier. Your task is to find it. Your function will receive two arguments - a `scales` object, and a ball count. The `scales` object has only one method: ```python get_weight(left, right) ``` where `left` and `right` are arrays of numbers of balls to put on left and right pan respectively. If the method returns `-1` - left pan is heavier If the method returns `1` - right pan is heavier If the method returns `0` - both pans weigh the same So what makes this the "ubermaster" version of this kata? First, it's not restricted to 8 balls as in the previous versions - your solution has to work for 8-500 balls. Second, you can't use the scale any more than mathematically necessary. Here's a chart: ball count | uses ----------------- 0-9 | 2 10-27 | 3 28-81 | 4 82-243 | 5 244-500 | 6 Too hard? Try lower levels by [tiriana](http://www.codewars.com/users/tiriana): * [novice](http://www.codewars.com/kata/544047f0cf362503e000036e) * [conqueror](http://www.codewars.com/kata/54404a06cf36258b08000364) * [master](http://www.codewars.com/kata/find-heavy-ball-level-master)
def find_ball(scales, ball_count): return find(scales,[*range(ball_count)]) def find(scales,balls): l=len(balls) if l==1: return balls[0] l=-(l//-3) a,b,c=balls[:l],balls[l:l+l],balls[l+l:] v=scales.get_weight(a, b) if v==-1: return find(scales,a) if v==1: return find(scales,b) return find(scales,c)
There are a **n** balls numbered from 0 to **n-1** (0,1,2,3,etc). Most of them have the same weight, but one is heavier. Your task is to find it. Your function will receive two arguments - a `scales` object, and a ball count. The `scales` object has only one method: ```python get_weight(left, right) ``` where `left` and `right` are arrays of numbers of balls to put on left and right pan respectively. If the method returns `-1` - left pan is heavier If the method returns `1` - right pan is heavier If the method returns `0` - both pans weigh the same So what makes this the "ubermaster" version of this kata? First, it's not restricted to 8 balls as in the previous versions - your solution has to work for 8-500 balls. Second, you can't use the scale any more than mathematically necessary. Here's a chart: ball count | uses ----------------- 0-9 | 2 10-27 | 3 28-81 | 4 82-243 | 5 244-500 | 6 Too hard? Try lower levels by [tiriana](http://www.codewars.com/users/tiriana): * [novice](http://www.codewars.com/kata/544047f0cf362503e000036e) * [conqueror](http://www.codewars.com/kata/54404a06cf36258b08000364) * [master](http://www.codewars.com/kata/find-heavy-ball-level-master)
def find_ball(scales, n=8): balls = list(range(n)) while len(balls) > 1: left, right, out = balls[::3], balls[1::3], balls[2::3] if len(balls) % 3 == 1: out.append(left.pop()) balls = [left, out, right][scales.get_weight(left, right) + 1] return balls.pop()
[Harshad numbers](http://en.wikipedia.org/wiki/Harshad_number) (also called Niven numbers) are positive numbers that can be divided (without remainder) by the sum of their digits. For example, the following numbers are Harshad numbers: * 10, because 1 + 0 = 1 and 10 is divisible by 1 * 27, because 2 + 7 = 9 and 27 is divisible by 9 * 588, because 5 + 8 + 8 = 21 and 588 is divisible by 21 While these numbers are not: * 19, because 1 + 9 = 10 and 19 is not divisible by 10 * 589, because 5 + 8 + 9 = 22 and 589 is not divisible by 22 * 1001, because 1 + 1 = 2 and 1001 is not divisible by 2 Harshad numbers can be found in any number base, but we are going to focus on base 10 exclusively. ## Your task Your task is to complete the skeleton Harshad object ("static class") which has 3 functions: * ```isValid()``` that checks if `n` is a Harshad number or not * ```getNext()``` that returns the next Harshad number > `n` * ```getSerie()``` that returns a series of `n` Harshad numbers, optional `start` value not included You do not need to care about the passed parameters in the test cases, they will always be valid integers (except for the start argument in `getSerie()` which is optional and should default to `0`). **Note:** only the first 2000 Harshad numbers will be checked in the tests. ## Examples ```python Harshad.is_valid(1) ==> True Harshad.get_next(0) ==> 1 Harshad.get_series(3) ==> [ 1, 2, 3 ] Harshad.get_series(3, 1000) ==> [ 1002, 1008, 1010 ] ```
from itertools import count, islice class Harshad: @staticmethod def is_valid(number): return number % sum(map(int, str(number))) == 0 @classmethod def get_next(cls, number): return next(i for i in count(number+1) if cls.is_valid(i)) @classmethod def get_series(cls, c, start=0): return list(islice(filter(cls.is_valid, (i for i in count(start+1))), c))
[Harshad numbers](http://en.wikipedia.org/wiki/Harshad_number) (also called Niven numbers) are positive numbers that can be divided (without remainder) by the sum of their digits. For example, the following numbers are Harshad numbers: * 10, because 1 + 0 = 1 and 10 is divisible by 1 * 27, because 2 + 7 = 9 and 27 is divisible by 9 * 588, because 5 + 8 + 8 = 21 and 588 is divisible by 21 While these numbers are not: * 19, because 1 + 9 = 10 and 19 is not divisible by 10 * 589, because 5 + 8 + 9 = 22 and 589 is not divisible by 22 * 1001, because 1 + 1 = 2 and 1001 is not divisible by 2 Harshad numbers can be found in any number base, but we are going to focus on base 10 exclusively. ## Your task Your task is to complete the skeleton Harshad object ("static class") which has 3 functions: * ```isValid()``` that checks if `n` is a Harshad number or not * ```getNext()``` that returns the next Harshad number > `n` * ```getSerie()``` that returns a series of `n` Harshad numbers, optional `start` value not included You do not need to care about the passed parameters in the test cases, they will always be valid integers (except for the start argument in `getSerie()` which is optional and should default to `0`). **Note:** only the first 2000 Harshad numbers will be checked in the tests. ## Examples ```python Harshad.is_valid(1) ==> True Harshad.get_next(0) ==> 1 Harshad.get_series(3) ==> [ 1, 2, 3 ] Harshad.get_series(3, 1000) ==> [ 1002, 1008, 1010 ] ```
class Harshad: @staticmethod def is_valid(number): return number % sum(map(int,str(number))) == 0 @staticmethod def get_next(number): n = number + 1 while not Harshad.is_valid(n): n += 1 return n @staticmethod def get_series(count, start=0): result = [Harshad.get_next(start)] for _ in range(count-1): result.append(Harshad.get_next(result[-1])) return result
[Harshad numbers](http://en.wikipedia.org/wiki/Harshad_number) (also called Niven numbers) are positive numbers that can be divided (without remainder) by the sum of their digits. For example, the following numbers are Harshad numbers: * 10, because 1 + 0 = 1 and 10 is divisible by 1 * 27, because 2 + 7 = 9 and 27 is divisible by 9 * 588, because 5 + 8 + 8 = 21 and 588 is divisible by 21 While these numbers are not: * 19, because 1 + 9 = 10 and 19 is not divisible by 10 * 589, because 5 + 8 + 9 = 22 and 589 is not divisible by 22 * 1001, because 1 + 1 = 2 and 1001 is not divisible by 2 Harshad numbers can be found in any number base, but we are going to focus on base 10 exclusively. ## Your task Your task is to complete the skeleton Harshad object ("static class") which has 3 functions: * ```isValid()``` that checks if `n` is a Harshad number or not * ```getNext()``` that returns the next Harshad number > `n` * ```getSerie()``` that returns a series of `n` Harshad numbers, optional `start` value not included You do not need to care about the passed parameters in the test cases, they will always be valid integers (except for the start argument in `getSerie()` which is optional and should default to `0`). **Note:** only the first 2000 Harshad numbers will be checked in the tests. ## Examples ```python Harshad.is_valid(1) ==> True Harshad.get_next(0) ==> 1 Harshad.get_series(3) ==> [ 1, 2, 3 ] Harshad.get_series(3, 1000) ==> [ 1002, 1008, 1010 ] ```
# generate the first ~2000 elements HARSHAD = [ n for n in range(1, 13000) if n % sum(map(int, str(n))) == 0 ] from bisect import bisect class Harshad: @staticmethod def is_valid(n): return n in HARSHAD @staticmethod def get_next(n): return HARSHAD[ bisect(HARSHAD, n) ] @staticmethod def get_series(cnt, n=0): start = bisect(HARSHAD, n) return HARSHAD[ start : start+cnt ]
[Harshad numbers](http://en.wikipedia.org/wiki/Harshad_number) (also called Niven numbers) are positive numbers that can be divided (without remainder) by the sum of their digits. For example, the following numbers are Harshad numbers: * 10, because 1 + 0 = 1 and 10 is divisible by 1 * 27, because 2 + 7 = 9 and 27 is divisible by 9 * 588, because 5 + 8 + 8 = 21 and 588 is divisible by 21 While these numbers are not: * 19, because 1 + 9 = 10 and 19 is not divisible by 10 * 589, because 5 + 8 + 9 = 22 and 589 is not divisible by 22 * 1001, because 1 + 1 = 2 and 1001 is not divisible by 2 Harshad numbers can be found in any number base, but we are going to focus on base 10 exclusively. ## Your task Your task is to complete the skeleton Harshad object ("static class") which has 3 functions: * ```isValid()``` that checks if `n` is a Harshad number or not * ```getNext()``` that returns the next Harshad number > `n` * ```getSerie()``` that returns a series of `n` Harshad numbers, optional `start` value not included You do not need to care about the passed parameters in the test cases, they will always be valid integers (except for the start argument in `getSerie()` which is optional and should default to `0`). **Note:** only the first 2000 Harshad numbers will be checked in the tests. ## Examples ```python Harshad.is_valid(1) ==> True Harshad.get_next(0) ==> 1 Harshad.get_series(3) ==> [ 1, 2, 3 ] Harshad.get_series(3, 1000) ==> [ 1002, 1008, 1010 ] ```
class Harshad: @staticmethod def is_valid(number): a =list(str(number)) shu = 0 for i in a: shu +=int(i) if number % shu ==0: return True else: return False @staticmethod def get_next(number): temp = number while 1: temp +=1 if Harshad.is_valid(temp): return temp @staticmethod def get_series(count, start=0): result = [] for i in range(count): a = Harshad.get_next(start) result.append(a) start = a return result
[Harshad numbers](http://en.wikipedia.org/wiki/Harshad_number) (also called Niven numbers) are positive numbers that can be divided (without remainder) by the sum of their digits. For example, the following numbers are Harshad numbers: * 10, because 1 + 0 = 1 and 10 is divisible by 1 * 27, because 2 + 7 = 9 and 27 is divisible by 9 * 588, because 5 + 8 + 8 = 21 and 588 is divisible by 21 While these numbers are not: * 19, because 1 + 9 = 10 and 19 is not divisible by 10 * 589, because 5 + 8 + 9 = 22 and 589 is not divisible by 22 * 1001, because 1 + 1 = 2 and 1001 is not divisible by 2 Harshad numbers can be found in any number base, but we are going to focus on base 10 exclusively. ## Your task Your task is to complete the skeleton Harshad object ("static class") which has 3 functions: * ```isValid()``` that checks if `n` is a Harshad number or not * ```getNext()``` that returns the next Harshad number > `n` * ```getSerie()``` that returns a series of `n` Harshad numbers, optional `start` value not included You do not need to care about the passed parameters in the test cases, they will always be valid integers (except for the start argument in `getSerie()` which is optional and should default to `0`). **Note:** only the first 2000 Harshad numbers will be checked in the tests. ## Examples ```python Harshad.is_valid(1) ==> True Harshad.get_next(0) ==> 1 Harshad.get_series(3) ==> [ 1, 2, 3 ] Harshad.get_series(3, 1000) ==> [ 1002, 1008, 1010 ] ```
class Harshad: @staticmethod def is_valid(number): a=list(str(number)) shu=0 for i in a: shu+=int(i) return True if not (number%shu) else False @staticmethod def get_next(number): temp=number while 1: temp+=1 if Harshad.is_valid(temp): return temp @staticmethod def get_series(count, start=0): result=[] for i in range(count): a=Harshad.get_next(start) result.append(a) start=a return result
[Harshad numbers](http://en.wikipedia.org/wiki/Harshad_number) (also called Niven numbers) are positive numbers that can be divided (without remainder) by the sum of their digits. For example, the following numbers are Harshad numbers: * 10, because 1 + 0 = 1 and 10 is divisible by 1 * 27, because 2 + 7 = 9 and 27 is divisible by 9 * 588, because 5 + 8 + 8 = 21 and 588 is divisible by 21 While these numbers are not: * 19, because 1 + 9 = 10 and 19 is not divisible by 10 * 589, because 5 + 8 + 9 = 22 and 589 is not divisible by 22 * 1001, because 1 + 1 = 2 and 1001 is not divisible by 2 Harshad numbers can be found in any number base, but we are going to focus on base 10 exclusively. ## Your task Your task is to complete the skeleton Harshad object ("static class") which has 3 functions: * ```isValid()``` that checks if `n` is a Harshad number or not * ```getNext()``` that returns the next Harshad number > `n` * ```getSerie()``` that returns a series of `n` Harshad numbers, optional `start` value not included You do not need to care about the passed parameters in the test cases, they will always be valid integers (except for the start argument in `getSerie()` which is optional and should default to `0`). **Note:** only the first 2000 Harshad numbers will be checked in the tests. ## Examples ```python Harshad.is_valid(1) ==> True Harshad.get_next(0) ==> 1 Harshad.get_series(3) ==> [ 1, 2, 3 ] Harshad.get_series(3, 1000) ==> [ 1002, 1008, 1010 ] ```
class Harshad(object): harshad = [n for n in range(1, 12534) if n % sum(int(d) for d in str(n)) == 0] @staticmethod def is_valid(number): return number in Harshad.harshad @staticmethod def get_next(number): return next(n for n in Harshad.harshad if n > number) @staticmethod def get_series(count, start=0): i = Harshad.harshad.index(Harshad.get_next(start)) return Harshad.harshad[i:i+count]
[Harshad numbers](http://en.wikipedia.org/wiki/Harshad_number) (also called Niven numbers) are positive numbers that can be divided (without remainder) by the sum of their digits. For example, the following numbers are Harshad numbers: * 10, because 1 + 0 = 1 and 10 is divisible by 1 * 27, because 2 + 7 = 9 and 27 is divisible by 9 * 588, because 5 + 8 + 8 = 21 and 588 is divisible by 21 While these numbers are not: * 19, because 1 + 9 = 10 and 19 is not divisible by 10 * 589, because 5 + 8 + 9 = 22 and 589 is not divisible by 22 * 1001, because 1 + 1 = 2 and 1001 is not divisible by 2 Harshad numbers can be found in any number base, but we are going to focus on base 10 exclusively. ## Your task Your task is to complete the skeleton Harshad object ("static class") which has 3 functions: * ```isValid()``` that checks if `n` is a Harshad number or not * ```getNext()``` that returns the next Harshad number > `n` * ```getSerie()``` that returns a series of `n` Harshad numbers, optional `start` value not included You do not need to care about the passed parameters in the test cases, they will always be valid integers (except for the start argument in `getSerie()` which is optional and should default to `0`). **Note:** only the first 2000 Harshad numbers will be checked in the tests. ## Examples ```python Harshad.is_valid(1) ==> True Harshad.get_next(0) ==> 1 Harshad.get_series(3) ==> [ 1, 2, 3 ] Harshad.get_series(3, 1000) ==> [ 1002, 1008, 1010 ] ```
from itertools import count, islice D = {} class Harshad: @staticmethod def is_valid(number): return D.get(number, D.setdefault(number, not number % sum(map(int, str(number))))) @staticmethod def get_next(number): return next(filter(Harshad.is_valid, count(number+1))) @staticmethod def get_series(size, start=0): return list(islice(filter(Harshad.is_valid, count(start+1)), size))
[Harshad numbers](http://en.wikipedia.org/wiki/Harshad_number) (also called Niven numbers) are positive numbers that can be divided (without remainder) by the sum of their digits. For example, the following numbers are Harshad numbers: * 10, because 1 + 0 = 1 and 10 is divisible by 1 * 27, because 2 + 7 = 9 and 27 is divisible by 9 * 588, because 5 + 8 + 8 = 21 and 588 is divisible by 21 While these numbers are not: * 19, because 1 + 9 = 10 and 19 is not divisible by 10 * 589, because 5 + 8 + 9 = 22 and 589 is not divisible by 22 * 1001, because 1 + 1 = 2 and 1001 is not divisible by 2 Harshad numbers can be found in any number base, but we are going to focus on base 10 exclusively. ## Your task Your task is to complete the skeleton Harshad object ("static class") which has 3 functions: * ```isValid()``` that checks if `n` is a Harshad number or not * ```getNext()``` that returns the next Harshad number > `n` * ```getSerie()``` that returns a series of `n` Harshad numbers, optional `start` value not included You do not need to care about the passed parameters in the test cases, they will always be valid integers (except for the start argument in `getSerie()` which is optional and should default to `0`). **Note:** only the first 2000 Harshad numbers will be checked in the tests. ## Examples ```python Harshad.is_valid(1) ==> True Harshad.get_next(0) ==> 1 Harshad.get_series(3) ==> [ 1, 2, 3 ] Harshad.get_series(3, 1000) ==> [ 1002, 1008, 1010 ] ```
class Harshad: @staticmethod def get_list(n): '''得到位数字的列表''' result = [] while n: result.append(n % 10) n = n // 10 #逆序,按正常的顺序返回 result.reverse() return result # print(result) @staticmethod def is_valid(number): if number == 0: return False if number < 10: return True num_list = Harshad.get_list(number) mul = 0 for i in num_list: mul += i if number%mul == 0: return True else: return False @staticmethod def get_next(number): if number < 10: return number+1 number = number + 1 while 1: if Harshad.is_valid(number) == True: break number += 1 return number @staticmethod def get_series(count, start=0): ser_list = [] start = start + 1 while 1: if Harshad.is_valid(start) == True: ser_list.append(start) if len(ser_list) == count: break start += 1 return ser_list
[Harshad numbers](http://en.wikipedia.org/wiki/Harshad_number) (also called Niven numbers) are positive numbers that can be divided (without remainder) by the sum of their digits. For example, the following numbers are Harshad numbers: * 10, because 1 + 0 = 1 and 10 is divisible by 1 * 27, because 2 + 7 = 9 and 27 is divisible by 9 * 588, because 5 + 8 + 8 = 21 and 588 is divisible by 21 While these numbers are not: * 19, because 1 + 9 = 10 and 19 is not divisible by 10 * 589, because 5 + 8 + 9 = 22 and 589 is not divisible by 22 * 1001, because 1 + 1 = 2 and 1001 is not divisible by 2 Harshad numbers can be found in any number base, but we are going to focus on base 10 exclusively. ## Your task Your task is to complete the skeleton Harshad object ("static class") which has 3 functions: * ```isValid()``` that checks if `n` is a Harshad number or not * ```getNext()``` that returns the next Harshad number > `n` * ```getSerie()``` that returns a series of `n` Harshad numbers, optional `start` value not included You do not need to care about the passed parameters in the test cases, they will always be valid integers (except for the start argument in `getSerie()` which is optional and should default to `0`). **Note:** only the first 2000 Harshad numbers will be checked in the tests. ## Examples ```python Harshad.is_valid(1) ==> True Harshad.get_next(0) ==> 1 Harshad.get_series(3) ==> [ 1, 2, 3 ] Harshad.get_series(3, 1000) ==> [ 1002, 1008, 1010 ] ```
from bisect import bisect_right class Harshad: values, values_set = [], set() i = 1 while len(values) < 2000: if not i % sum(int(x) for x in str(i)): values.append(i) values_set.add(i) i += 1 @staticmethod def is_valid(n): return n in Harshad.values_set @staticmethod def get_next(n): return Harshad.values[bisect_right(Harshad.values, n)] @staticmethod def get_series(n, s=0): x = bisect_right(Harshad.values, s) return Harshad.values[x:x+n]
[Harshad numbers](http://en.wikipedia.org/wiki/Harshad_number) (also called Niven numbers) are positive numbers that can be divided (without remainder) by the sum of their digits. For example, the following numbers are Harshad numbers: * 10, because 1 + 0 = 1 and 10 is divisible by 1 * 27, because 2 + 7 = 9 and 27 is divisible by 9 * 588, because 5 + 8 + 8 = 21 and 588 is divisible by 21 While these numbers are not: * 19, because 1 + 9 = 10 and 19 is not divisible by 10 * 589, because 5 + 8 + 9 = 22 and 589 is not divisible by 22 * 1001, because 1 + 1 = 2 and 1001 is not divisible by 2 Harshad numbers can be found in any number base, but we are going to focus on base 10 exclusively. ## Your task Your task is to complete the skeleton Harshad object ("static class") which has 3 functions: * ```isValid()``` that checks if `n` is a Harshad number or not * ```getNext()``` that returns the next Harshad number > `n` * ```getSerie()``` that returns a series of `n` Harshad numbers, optional `start` value not included You do not need to care about the passed parameters in the test cases, they will always be valid integers (except for the start argument in `getSerie()` which is optional and should default to `0`). **Note:** only the first 2000 Harshad numbers will be checked in the tests. ## Examples ```python Harshad.is_valid(1) ==> True Harshad.get_next(0) ==> 1 Harshad.get_series(3) ==> [ 1, 2, 3 ] Harshad.get_series(3, 1000) ==> [ 1002, 1008, 1010 ] ```
class Harshad: @staticmethod def is_valid(number): if number == 0: return False sumdigits = sum(int(d) for d in str(number)) return number % sumdigits == 0 @staticmethod def get_next(number): while True: number += 1 if Harshad.is_valid(number): return number @staticmethod def get_series(count, start = 0): answer = [] for _ in range(count): start = Harshad.get_next(start) answer.append(start) return answer
Everyday we go to different places to get our things done. Those places can be represented by specific location points `[ [, ], ... ]` on a map. I will be giving you an array of arrays that contain coordinates of the different places I had been on a particular day. Your task will be to find `peripheries (outermost edges)` of the bounding box that contains all the points. The response should only contain `Northwest and Southeast` points as follows: `{ "nw": [, ], "se": [ , ] }`. You are adviced to draw the points on a 2D plan to visualize: ``` N ^ p(nw) ______________|________________ | | | | | all other | | | points | | | | ----------------------------------------> E | | | | all other | | | points | | |______________|________________| | p(se) ```
def box(coords): lat, long = zip(*coords) return {"nw": [max(lat), min(long)], "se": [min(lat), max(long)]}
Everyday we go to different places to get our things done. Those places can be represented by specific location points `[ [, ], ... ]` on a map. I will be giving you an array of arrays that contain coordinates of the different places I had been on a particular day. Your task will be to find `peripheries (outermost edges)` of the bounding box that contains all the points. The response should only contain `Northwest and Southeast` points as follows: `{ "nw": [, ], "se": [ , ] }`. You are adviced to draw the points on a 2D plan to visualize: ``` N ^ p(nw) ______________|________________ | | | | | all other | | | points | | | | ----------------------------------------> E | | | | all other | | | points | | |______________|________________| | p(se) ```
def box(coords): return { 'nw': [max(x for x, _ in coords), min(y for _, y in coords)], 'se': [min(x for x, _ in coords), max(y for _, y in coords)], }
Everyday we go to different places to get our things done. Those places can be represented by specific location points `[ [, ], ... ]` on a map. I will be giving you an array of arrays that contain coordinates of the different places I had been on a particular day. Your task will be to find `peripheries (outermost edges)` of the bounding box that contains all the points. The response should only contain `Northwest and Southeast` points as follows: `{ "nw": [, ], "se": [ , ] }`. You are adviced to draw the points on a 2D plan to visualize: ``` N ^ p(nw) ______________|________________ | | | | | all other | | | points | | | | ----------------------------------------> E | | | | all other | | | points | | |______________|________________| | p(se) ```
def box(coords): NS, EW = zip(*coords) return {"nw": [max(NS), min(EW)], "se": [min(NS), max(EW)]}