diff options
Diffstat (limited to 'challenge-273/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-273/sgreen/python/ch-1.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-273/sgreen/python/ch-1.py b/challenge-273/sgreen/python/ch-1.py new file mode 100755 index 0000000000..98188f53ab --- /dev/null +++ b/challenge-273/sgreen/python/ch-1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +from math import floor +import sys + + +def char_percentage(s: str, char: str) -> int: + """ + Calculates the percentage of a given character in a string. + + Args: + s (str): The input string. + char (str): The character to be counted. + + Returns: + int: The percentage of the character in the string. + """ + return floor(s.count(char) / len(s) * 100 + 0.5) + + +def main(): + result = char_percentage(sys.argv[1], sys.argv[2]) + print(result) + + +if __name__ == '__main__': + main() |
