This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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})" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# juggling_balls_game.py | |
import turtle | |
import time | |
import random | |
from juggling_balls import Ball | |
# Game parameters | |
WIDTH = 600 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# juggling_balls.py | |
import random | |
import turtle | |
class Ball(turtle.Turtle): | |
MAX_VELOCITY = 5 | |
GRAVITY = 0.07 | |
BAT_VELOCITY_CHANGE = 8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import turtle | |
import random | |
import time | |
image_size = 125 | |
falling_speed = 2 | |
max_time_interval = 3 | |
image = "snowflake-g3d31b3007_125.gif" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |