MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / new_game

Function new_game

example_code/item_076.py:150–165  ·  view source on GitHub ↗
(connection, lower, upper, secret)

Source from the content-addressed store, hash-verified

148
149@contextlib.contextmanager
150def new_game(connection, lower, upper, secret):
151 print(
152 f"Guess a number between {lower} and {upper}!"
153 f" Shhhhh, it's {secret}."
154 )
155 connection.send(f"PARAMS {lower} {upper}")
156 try:
157 yield ClientSession(
158 connection.send,
159 connection.receive,
160 secret,
161 )
162 finally:
163 # Make it so the output printing matches what you expect
164 time.sleep(0.1)
165 connection.send("CLEAR")
166
167
168print("Example 9")

Callers 1

run_clientFunction · 0.85

Calls 2

ClientSessionClass · 0.85
sendMethod · 0.45

Tested by

no test coverage detected