Skip to main content
added 2 characters in body
Source Link
Matt
  • 31
  • 2

TLDR: Looks good! This is perfectly reasonable solution for your problem. It's certainly not clumsy.

Optimisations The optimisation ShadowRanger points out, is faster, due to compiler optimisations, I wouldn't worry about this at a beginner level (and nonot even at an experienced level really, unless it was critical to make every optimisation).

The optimisation of checking only isupper or islower that some have pointed out probably isn't valid. If your input is guaranteed to be only alphabetic characters A-Z or a-z, then you can assume that if it's not upper, it's lower. But this doesn't apply generally. '1' is neither lower ornor upper for example. Checking only isupper and assuming the opposite on a False result, you would increment your 'lower' counter and that wouldn't be correct.

Your code provides a correct solution and doesn't break when the user inputs an empty string or non alphabetic characters, which is why I'd consider it good.

Possible next step: Since you say you're a beginner, I'd look up writing tests if you haven't already and learn a little about how to write good tests. Checking empty input and special characters would be an interesting start. Some terms to search would be edge-case

TLDR: Looks good! This is perfectly reasonable solution for your problem. It's certainly not clumsy.

Optimisations The optimisation ShadowRanger points out, is faster, due to compiler optimisations, I wouldn't worry about this at a beginner level (and no even at an experienced level really, unless it was critical to make every optimisation.

The optimisation of checking only isupper or islower that some have pointed out probably isn't valid. If your input is guaranteed to be only alphabetic characters A-Z or a-z, then you can assume that if it's not upper, it's lower. But this doesn't apply generally. '1' is neither lower or upper for example. Checking only isupper and assuming the opposite on a False result, you would increment your 'lower' counter and that wouldn't be correct.

Your code provides a correct solution and doesn't break when the user inputs an empty string or non alphabetic characters, which is why I'd consider it good.

Possible next step: Since you say you're a beginner, I'd look up writing tests if you haven't already and learn a little about how to write good tests. Checking empty input and special characters would be an interesting start. Some terms to search would be edge-case

TLDR: Looks good! This is perfectly reasonable solution for your problem. It's certainly not clumsy.

Optimisations The optimisation ShadowRanger points out, is faster, due to compiler optimisations, I wouldn't worry about this at a beginner level (and not even at an experienced level really, unless it was critical to make every optimisation).

The optimisation of checking only isupper or islower that some have pointed out probably isn't valid. If your input is guaranteed to be only alphabetic characters A-Z or a-z, then you can assume that if it's not upper, it's lower. But this doesn't apply generally. '1' is neither lower nor upper for example. Checking only isupper and assuming the opposite on a False result, you would increment your 'lower' counter and that wouldn't be correct.

Your code provides a correct solution and doesn't break when the user inputs an empty string or non alphabetic characters, which is why I'd consider it good.

Possible next step: Since you say you're a beginner, I'd look up writing tests if you haven't already and learn a little about how to write good tests. Checking empty input and special characters would be an interesting start. Some terms to search would be edge-case

Source Link
Matt
  • 31
  • 2

TLDR: Looks good! This is perfectly reasonable solution for your problem. It's certainly not clumsy.

Optimisations The optimisation ShadowRanger points out, is faster, due to compiler optimisations, I wouldn't worry about this at a beginner level (and no even at an experienced level really, unless it was critical to make every optimisation.

The optimisation of checking only isupper or islower that some have pointed out probably isn't valid. If your input is guaranteed to be only alphabetic characters A-Z or a-z, then you can assume that if it's not upper, it's lower. But this doesn't apply generally. '1' is neither lower or upper for example. Checking only isupper and assuming the opposite on a False result, you would increment your 'lower' counter and that wouldn't be correct.

Your code provides a correct solution and doesn't break when the user inputs an empty string or non alphabetic characters, which is why I'd consider it good.

Possible next step: Since you say you're a beginner, I'd look up writing tests if you haven't already and learn a little about how to write good tests. Checking empty input and special characters would be an interesting start. Some terms to search would be edge-case