Skip to content

Instantly share code, notes, and snippets.

class SubstackArticle:
   def __init__(self, number_of_words):
       self.number_of_words = number_of_words
   def __mul__(self, other):
       if isinstance(other, int):
           return SubstackArticle(self.number_of_words * other)
   def __rmul__(self, other):
       print("__rmul__ called")
class SubstackArticle:
   def __init__(self, number_of_words):
       self.number_of_words = number_of_words
   def __mul__(self, other):
       if isinstance(other, int):
           return SubstackArticle(self.number_of_words * other)
   def __rmul__(self, other):
       return self.__mul__(other)
class SubstackArticle:
   def __init__(self, number_of_words):
       self.number_of_words = number_of_words
   def __mul__(self, other):
       if isinstance(other, int):
           return SubstackArticle(self.number_of_words * other)
   def __repr__(self):
       return f"SubstackArticle({self.number_of_words})"
class SubstackArticle:
   def __init__(self, number_of_words):
       self.number_of_words = number_of_words
       
my_article = SubstackArticle(1000)
print(my_article * 3)
# TypeError: unsupported operand type(s) for *: 'SubstackArticle' and 'int'
import random
class Wizard:
def __init__(self, name, patronus, birth_year):
self.name = name
self.patronus = patronus
self.birth_year = birth_year
self.house = None
self.wand = None
self.skill = 0.2 # 0.0 (bad) to 1.0 (good)
# juggling_balls_game.py
import turtle
import time
import random
from juggling_balls import Ball
# Game parameters
WIDTH = 600
# juggling_balls.py
import random
import turtle
class Ball(turtle.Turtle):
MAX_VELOCITY = 5
GRAVITY = 0.07
BAT_VELOCITY_CHANGE = 8
import turtle
import random
import time
image_size = 125
falling_speed = 2
max_time_interval = 3
image = "snowflake-g3d31b3007_125.gif"
import turtle
import random
import time
speed = 5
max_interval = 0.3
window = turtle.Screen()
window.tracer(0)
window.bgcolor(0.2, 0.2, 0.2)
import turtle
import random
import time
speed = 5
max_interval = 0.3
window = turtle.Screen()
window.tracer(0)
window.bgcolor(0.2, 0.2, 0.2)