aboutsummaryrefslogtreecommitdiff
path: root/challenge-273/sgreen/python/ch-1.py
blob: 98188f53ab178dfa1ca65e7d57a387ed6e756090 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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()