def beats(selfother)if isinstance(otherrock)return none no winner elif isinstance(otherpaper)return other elif isinstance(otherscissors)return self elseraise typeerror("unknown second thing"class duckpaper(paper)def beats(selfother)if isinstance(otherrock)return self elif isinstance(otherpaper)return none no winner elif isinstance(otherscissors)return other elseraise typeerror("unknown second thing"class duckscissors(scissors)def beats(selfother)if isinstance(otherrock)return other elif isinstance(otherpaper)return self elif isinstance(otherscissors)return none no winner elseraise typeerror("unknown second thing"def beats (xy)if hasattr( 'beats')return beats(yelseraise typeerror("unknown first thing"rockpaperscissors duckrock()duckpaper()duckscissors(beats (rockpaperbeats ( rocktypeerrorunknown first thing we haven' actually reduced the amount of codebut this version somewhat reduces the complexity within each individual callableand reduces the level of nested conditionals by one most of the logic is pushed into separate classes rather than deep branching in multiple dispatch