Some suggestions:
Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a
Player
class could have ascore
field and aGame
class could have arounds
field and aroll
method:MAX_ROUNDS = 5 class Player: def __init__(self): self.score = 0 def win(self): self.score += 10 def lose(self): self.score -= 5 class Game: rounds = 0 player_1 = Player() player_2 = Player() def play(): if self.rounds >= MAX_ROUNDS: ... else: ... self.rounds += 1
Dependency injection of
randint
andinput
would allow this code to be unit tested.If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the
sleep
s.
Some suggestions:
Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a
Player
class could have ascore
field and aGame
class could have arounds
field and aroll
method:MAX_ROUNDS = 5 class Player: score = 0 def win(self): self.score += 10 def lose(self): self.score -= 5 class Game: rounds = 0 player_1 = Player() player_2 = Player() def play(): if self.rounds >= MAX_ROUNDS: ... else: ... self.rounds += 1
Dependency injection of
randint
andinput
would allow this code to be unit tested.If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the
sleep
s.
Some suggestions:
Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a
Player
class could have ascore
field and aGame
class could have arounds
field and aroll
method:MAX_ROUNDS = 5 class Player: def __init__(self): self.score = 0 def win(self): self.score += 10 def lose(self): self.score -= 5 class Game: rounds = 0 player_1 = Player() player_2 = Player() def play(): if self.rounds >= MAX_ROUNDS: ... else: ... self.rounds += 1
Dependency injection of
randint
andinput
would allow this code to be unit tested.If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the
sleep
s.
Some suggestions:
- Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a
Player
class could have ascore
field and aGame
class could have arounds
field and aroll
method.Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a
Player
class could have ascore
field and aGame
class could have arounds
field and aroll
method:MAX_ROUNDS = 5 class Player: score = 0 def win(self): self.score += 10 def lose(self): self.score -= 5 class Game: rounds = 0 player_1 = Player() player_2 = Player() def play(): if self.rounds >= MAX_ROUNDS: ... else: ... self.rounds += 1
- Dependency injection of
randint
andinput
would allow this code to be unit tested.Dependency injection of
randint
andinput
would allow this code to be unit tested. - If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the
sleep
s.If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the
sleep
s.
Some suggestions:
- Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a
Player
class could have ascore
field and aGame
class could have arounds
field and aroll
method. - Dependency injection of
randint
andinput
would allow this code to be unit tested. - If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the
sleep
s.
Some suggestions:
Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a
Player
class could have ascore
field and aGame
class could have arounds
field and aroll
method:MAX_ROUNDS = 5 class Player: score = 0 def win(self): self.score += 10 def lose(self): self.score -= 5 class Game: rounds = 0 player_1 = Player() player_2 = Player() def play(): if self.rounds >= MAX_ROUNDS: ... else: ... self.rounds += 1
Dependency injection of
randint
andinput
would allow this code to be unit tested.If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the
sleep
s.
Some suggestions:
- Pulling out functions or classes w/methods will allow you to reduce the amount of nesting in the code, and at the same time will package the code into easily understood functionally and semantically separate parts. This is incredibly important in larger programs, but can also highlight ways in which existing shorter programs can be structured for maintainability. For example, a
Player
class could have ascore
field and aGame
class could have arounds
field and aroll
method. - Dependency injection of
randint
andinput
would allow this code to be unit tested. - If someone wants to play this a lot they would probably not appreciate the "dramatic pause" before showing the result of the rolls. I would simply get rid of the
sleep
s.