Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Style

You've styled your code very well overall, I just have a few small nitpicky tips and such.

  • First off, when running main, you need run it under an if __name__ == "__main__": block. See this Stack Overflow answer this Stack Overflow answer for more information on this.

  • The comment at the top of your code file should be a docstring. It should look something like the below example, with a description of the file and it's contents.

     """
     filename.py
     Put a description of your file here.
     """
    

Design

Your design is not as great as your coding style, so I'm going to go more in-depth here on what can be improved.

  • At the top of main you have a lot of print statements on one line. I'd reccomend defining a function to easily print a lot of lines without needing to repeat print statements.

     def print_lines(*lines):
     """
     A helpful function for printing many
     separate strings on separate lines.
     """
     print("\n".join([line for line in lines]))
     # EXAMPLE USAGE
     print_lines(
     "Hello.",
     "Goodbye"
     )
    
  • Your current design using variables to manage different statistics and attributes about a player and an enemy begs for Object-Oriented-Programming. I'd recommend setting up something like this, a Character class with methods like, do_damage, or take_damage.

     class Character:
     """
     Base class used to create playable
     characters
     """
     def __init__(self, health: int, damage: int, name: str):
     self.health = health
     self.damage = damage
     self.name = name
     ...
    
  • Another thing I'd recommend is using dictionaries for getting certain inputs, rather than creating if/elif/else chains. Here's an example.

     CHOICES = {
     "a choice": a_function,
     ...
     }
     user_input = raw_input("> ")
     if user_input in CHOICES:
     CHOICES[user_input]()
    
  • Finally, I'd recommend trimming of useless whitespace from user input, in addition to lowering the input. This makes user input more forgiving.

Anyways, that's about all I can come up with. if there's anything else that you want me to cover, just mention it in the comments, and I'll see what I can do. I hope this helps!

Style

You've styled your code very well overall, I just have a few small nitpicky tips and such.

  • First off, when running main, you need run it under an if __name__ == "__main__": block. See this Stack Overflow answer for more information on this.

  • The comment at the top of your code file should be a docstring. It should look something like the below example, with a description of the file and it's contents.

     """
     filename.py
     Put a description of your file here.
     """
    

Design

Your design is not as great as your coding style, so I'm going to go more in-depth here on what can be improved.

  • At the top of main you have a lot of print statements on one line. I'd reccomend defining a function to easily print a lot of lines without needing to repeat print statements.

     def print_lines(*lines):
     """
     A helpful function for printing many
     separate strings on separate lines.
     """
     print("\n".join([line for line in lines]))
     # EXAMPLE USAGE
     print_lines(
     "Hello.",
     "Goodbye"
     )
    
  • Your current design using variables to manage different statistics and attributes about a player and an enemy begs for Object-Oriented-Programming. I'd recommend setting up something like this, a Character class with methods like, do_damage, or take_damage.

     class Character:
     """
     Base class used to create playable
     characters
     """
     def __init__(self, health: int, damage: int, name: str):
     self.health = health
     self.damage = damage
     self.name = name
     ...
    
  • Another thing I'd recommend is using dictionaries for getting certain inputs, rather than creating if/elif/else chains. Here's an example.

     CHOICES = {
     "a choice": a_function,
     ...
     }
     user_input = raw_input("> ")
     if user_input in CHOICES:
     CHOICES[user_input]()
    
  • Finally, I'd recommend trimming of useless whitespace from user input, in addition to lowering the input. This makes user input more forgiving.

Anyways, that's about all I can come up with. if there's anything else that you want me to cover, just mention it in the comments, and I'll see what I can do. I hope this helps!

Style

You've styled your code very well overall, I just have a few small nitpicky tips and such.

  • First off, when running main, you need run it under an if __name__ == "__main__": block. See this Stack Overflow answer for more information on this.

  • The comment at the top of your code file should be a docstring. It should look something like the below example, with a description of the file and it's contents.

     """
     filename.py
     Put a description of your file here.
     """
    

Design

Your design is not as great as your coding style, so I'm going to go more in-depth here on what can be improved.

  • At the top of main you have a lot of print statements on one line. I'd reccomend defining a function to easily print a lot of lines without needing to repeat print statements.

     def print_lines(*lines):
     """
     A helpful function for printing many
     separate strings on separate lines.
     """
     print("\n".join([line for line in lines]))
     # EXAMPLE USAGE
     print_lines(
     "Hello.",
     "Goodbye"
     )
    
  • Your current design using variables to manage different statistics and attributes about a player and an enemy begs for Object-Oriented-Programming. I'd recommend setting up something like this, a Character class with methods like, do_damage, or take_damage.

     class Character:
     """
     Base class used to create playable
     characters
     """
     def __init__(self, health: int, damage: int, name: str):
     self.health = health
     self.damage = damage
     self.name = name
     ...
    
  • Another thing I'd recommend is using dictionaries for getting certain inputs, rather than creating if/elif/else chains. Here's an example.

     CHOICES = {
     "a choice": a_function,
     ...
     }
     user_input = raw_input("> ")
     if user_input in CHOICES:
     CHOICES[user_input]()
    
  • Finally, I'd recommend trimming of useless whitespace from user input, in addition to lowering the input. This makes user input more forgiving.

Anyways, that's about all I can come up with. if there's anything else that you want me to cover, just mention it in the comments, and I'll see what I can do. I hope this helps!

Improved Formatting
Source Link
Quill
  • 12k
  • 5
  • 41
  • 93

Style

You've styled your code very well overall, I just have a few small nitpicky tips and such.

  • First off, when running main, you need run it under an if __name__ == "__main__": block. See this StackoverflowStack Overflow answer for more information on this.

  • The comment at the top of your code file should be a docstring. It should look something like the below example, with a description of the file and it's contents.

     """
     filename.py
     Put a description of your file here.
     """
    

Design

Your design is not as great as your coding style, so I'm going to go more in-depth here on what can be improved.

  • At the top of main you have a lot of print statements on one line. I'd reccomend defining a function to easily print a lot of lines without needing to repeat print statements.

     def print_lines(*lines):
     """
     A helpful function for printing many
     separate strings on separate lines.
     """
     print("\n".join([line for line in lines]))
     # EXAMPLE USAGE
     print_lines(
     "Hello.",
     "Goodbye"
     )
    
  • Your current design using variables to manage different statistics and attributes about a player and an enemy begs for Object-Oriented-Programming. I'd recommend setting up something like this, a Character class with methods like, do_damage, or take_damage.

     class Character:
     """
     Base class used to create playable
     characters
     """
     def __init__(self, health: int, damage: int, name: str):
     self.health = health
     self.damage = damage
     self.name = name
     ...
    
  • Another thing I'd recommend is using dictionaries for getting certain inputs, rather than creating if/elif/else chains. Here's an example.

     CHOICES = {
     "a choice": a_function,
     ...
     }
     user_input = raw_input("> ")
     if user_input in CHOICES:
     CHOICES[user_input]()
    
  • Finally, I'd recommend trimming of useless whitespace from user input, in addition to lowering the input. This makes user input more forgiving.

Anyways, that's about all I can come up with. if there's anything else that you want me to cover, just mention it in the comments, and I'll see what I can do. I hope this helps!

Style

You've styled your code very well overall, I just have a few small nitpicky tips and such.

  • First off, when running main, you need run it under an if __name__ == "__main__": block. See this Stackoverflow answer for more information on this.

  • The comment at the top of your code file should be a docstring. It should look something like the below example, with a description of the file and it's contents.

     """
     filename.py
     Put a description of your file here.
     """
    

Design

Your design is not as great as your coding style, so I'm going to go more in-depth here on what can be improved.

  • At the top of main you have a lot of print statements on one line. I'd reccomend defining a function to easily print a lot of lines without needing to repeat print statements.

     def print_lines(*lines):
     """
     A helpful function for printing many
     separate strings on separate lines.
     """
     print("\n".join([line for line in lines]))
     # EXAMPLE USAGE
     print_lines(
     "Hello.",
     "Goodbye"
     )
    
  • Your current design using variables to manage different statistics and attributes about a player and an enemy begs for Object-Oriented-Programming. I'd recommend setting up something like this, a Character class with methods like, do_damage, or take_damage.

     class Character:
     """
     Base class used to create playable
     characters
     """
     def __init__(self, health: int, damage: int, name: str):
     self.health = health
     self.damage = damage
     self.name = name
     ...
    
  • Another thing I'd recommend is using dictionaries for getting certain inputs, rather than creating if/elif/else chains. Here's an example.

     CHOICES = {
     "a choice": a_function,
     ...
     }
     user_input = raw_input("> ")
     if user_input in CHOICES:
     CHOICES[user_input]()
    
  • Finally, I'd recommend trimming of useless whitespace from user input, in addition to lowering the input. This makes user input more forgiving.

Anyways, that's about all I can come up with. if there's anything else that you want me to cover, just mention it in the comments, and I'll see what I can do. I hope this helps!

Style

You've styled your code very well overall, I just have a few small nitpicky tips and such.

  • First off, when running main, you need run it under an if __name__ == "__main__": block. See this Stack Overflow answer for more information on this.

  • The comment at the top of your code file should be a docstring. It should look something like the below example, with a description of the file and it's contents.

     """
     filename.py
     Put a description of your file here.
     """
    

Design

Your design is not as great as your coding style, so I'm going to go more in-depth here on what can be improved.

  • At the top of main you have a lot of print statements on one line. I'd reccomend defining a function to easily print a lot of lines without needing to repeat print statements.

     def print_lines(*lines):
     """
     A helpful function for printing many
     separate strings on separate lines.
     """
     print("\n".join([line for line in lines]))
     # EXAMPLE USAGE
     print_lines(
     "Hello.",
     "Goodbye"
     )
    
  • Your current design using variables to manage different statistics and attributes about a player and an enemy begs for Object-Oriented-Programming. I'd recommend setting up something like this, a Character class with methods like, do_damage, or take_damage.

     class Character:
     """
     Base class used to create playable
     characters
     """
     def __init__(self, health: int, damage: int, name: str):
     self.health = health
     self.damage = damage
     self.name = name
     ...
    
  • Another thing I'd recommend is using dictionaries for getting certain inputs, rather than creating if/elif/else chains. Here's an example.

     CHOICES = {
     "a choice": a_function,
     ...
     }
     user_input = raw_input("> ")
     if user_input in CHOICES:
     CHOICES[user_input]()
    
  • Finally, I'd recommend trimming of useless whitespace from user input, in addition to lowering the input. This makes user input more forgiving.

Anyways, that's about all I can come up with. if there's anything else that you want me to cover, just mention it in the comments, and I'll see what I can do. I hope this helps!

added 8 characters in body
Source Link
Ethan Bierlein
  • 15.9k
  • 4
  • 60
  • 146

Style

Your style is actually quite nice!You've styled your code very well overall, I just have a few small nitpicky tips and such.

  • First off, when running main, you need run it under an if __name__ == "__main__": block. See this Stackoverflow answer for more information on this.

  • The comment at the top of your code file should be a docstring. It should look something like the below example, with a description of the file and it's contents.

     """
     filename.py
     Put a description of your file here.
     """
    

Design

Your design is not as great as your coding style, so I'm going to go more in-depth here on what can be improved.

  • At the top of main you have a lot of print statements on one line. I'd reccomend defining a function to easily print a lot of lines without needing to repeat print statements.

     def print_lines(*lines):
     """
     A helpful function for printing many
     separate strings on separate lines.
     """
     print("\n".join([line for line in lines]))
     # EXAMPLE USAGE
     print_lines(
     "Hello.",
     "Goodbye"
     )
    
  • Your current design using variables to manage different statistics and attributes about a player and an enemy begs for Object-Oriented-Programming. I'd recommend setting up something like this, a Character class with methods like, do_damage, or take_damage.

     class Character:
     """
     Base class used to create playable
     characters
     """
     def __init__(self, health: int, damage: int, name: str):
     self.health = health
     self.damage = damage
     self.name = name
     ...
    
  • Another thing I'd recommend is using dictionaries for getting certain inputs, rather than creating if/elif/else chains. Here's an example.

     CHOICES = {
     "a choice": a_function,
     ...
     }
     user_input = raw_input("> ")
     if user_input in CHOICES:
     CHOICES[user_input]()
    
  • Finally, I'd recommend trimming of useless whitespace from user input, in addition to lowering the input. This makes user input more forgiving.

Anyways, that's about all I can come up with. if there's anything else that you want me to cover, just mention it in the comments, and I'll see what I can do. I hope this helps!

Style

Your style is actually quite nice! I just have a few small nitpicky tips and such.

  • First off, when running main, you need run it under an if __name__ == "__main__": block. See this Stackoverflow answer for more information on this.

  • The comment at the top of your code file should be a docstring. It should look something like the below example, with a description of the file and it's contents.

     """
     filename.py
     Put a description of your file here.
     """
    

Design

Your design is not as great as your coding style, so I'm going to go more in-depth here on what can be improved.

  • At the top of main you have a lot of print statements on one line. I'd reccomend defining a function to easily print a lot of lines without needing to repeat print statements.

     def print_lines(*lines):
     """
     A helpful function for printing many
     separate strings on separate lines.
     """
     print("\n".join([line for line in lines]))
     # EXAMPLE USAGE
     print_lines(
     "Hello.",
     "Goodbye"
     )
    
  • Your current design using variables to manage different statistics and attributes about a player and an enemy begs for Object-Oriented-Programming. I'd recommend setting up something like this, a Character class with methods like, do_damage, or take_damage.

     class Character:
     """
     Base class used to create playable
     characters
     """
     def __init__(self, health: int, damage: int, name: str):
     self.health = health
     self.damage = damage
     self.name = name
     ...
    
  • Another thing I'd recommend is using dictionaries for getting certain inputs, rather than creating if/elif/else chains. Here's an example.

     CHOICES = {
     "a choice": a_function,
     ...
     }
     user_input = raw_input("> ")
     if user_input in CHOICES:
     CHOICES[user_input]()
    
  • Finally, I'd recommend trimming of useless whitespace from user input, in addition to lowering the input. This makes user input more forgiving.

Anyways, that's about all I can come up with. if there's anything else that you want me to cover, just mention it in the comments, and I'll see what I can do. I hope this helps!

Style

You've styled your code very well overall, I just have a few small nitpicky tips and such.

  • First off, when running main, you need run it under an if __name__ == "__main__": block. See this Stackoverflow answer for more information on this.

  • The comment at the top of your code file should be a docstring. It should look something like the below example, with a description of the file and it's contents.

     """
     filename.py
     Put a description of your file here.
     """
    

Design

Your design is not as great as your coding style, so I'm going to go more in-depth here on what can be improved.

  • At the top of main you have a lot of print statements on one line. I'd reccomend defining a function to easily print a lot of lines without needing to repeat print statements.

     def print_lines(*lines):
     """
     A helpful function for printing many
     separate strings on separate lines.
     """
     print("\n".join([line for line in lines]))
     # EXAMPLE USAGE
     print_lines(
     "Hello.",
     "Goodbye"
     )
    
  • Your current design using variables to manage different statistics and attributes about a player and an enemy begs for Object-Oriented-Programming. I'd recommend setting up something like this, a Character class with methods like, do_damage, or take_damage.

     class Character:
     """
     Base class used to create playable
     characters
     """
     def __init__(self, health: int, damage: int, name: str):
     self.health = health
     self.damage = damage
     self.name = name
     ...
    
  • Another thing I'd recommend is using dictionaries for getting certain inputs, rather than creating if/elif/else chains. Here's an example.

     CHOICES = {
     "a choice": a_function,
     ...
     }
     user_input = raw_input("> ")
     if user_input in CHOICES:
     CHOICES[user_input]()
    
  • Finally, I'd recommend trimming of useless whitespace from user input, in addition to lowering the input. This makes user input more forgiving.

Anyways, that's about all I can come up with. if there's anything else that you want me to cover, just mention it in the comments, and I'll see what I can do. I hope this helps!

Source Link
Ethan Bierlein
  • 15.9k
  • 4
  • 60
  • 146
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /