Skip to main content
Code Review

Return to Revisions

3 of 5
replaced http://softwareengineering.stackexchange.com/ with https://softwareengineering.stackexchange.com/

I'd say the code is not bad, just a few style issues and a couple of practical things.

  • You don't need two lines to lowercase the input string, you can do directly

inp = input('Input the text you want to code:\n').lower()

  • You're not checking user input, if the second input is not an integer, int() will generate a ValueError. You should put a try/catch around that.

  • Your input implies that numbers lower than 1 and higher than 25 are not acceptable, while actually you're accepting them and doing something different than what you told the user. Either you generate an error and refuse the input, or you say that the input will be modified accordingly. Either way the user should know what's going on.

  • You have quite a few hard-coded values, consider using constants .

  • The comment # If the final number is greater than 122.. is useless, the code is clear at that point.

  • The comment # Function to code a text with caeser chyper. should actually be a docstring . You should also specify what you expect as input and what kind of output you return.

  • I would rename the variable input to input_string , just so it's not the same name of the input() function.

  • elif((num + key <= 122)): is actually just else:

  • You're printing inside of the function. I'd return the value and let the caller decide what to do with it.

  • You may want to consider putting if __name__ == "__main__": in your code and call your function from there.

  • This is a simple function, so no need to dig too deep but if you want, you may have a look here about string concatenation .

ChatterOne
  • 2.8k
  • 12
  • 18
default

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