aboutsummaryrefslogtreecommitdiff
path: root/challenge-282/sgreen/python/ch-2.py
blob: 4673e3aef726f19fb923c6e9064a35e6d06cf471 (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
28
29
30
31
32
#!/usr/bin/env python3

import sys


def key_changes(s: str) -> int:
    # Convert the string to lower case
    s = s.lower()

    # Start with the first letter
    current_key = s[0]

    # Count the number of times we change keys
    changes = 0

    for letter in s:
        if letter != current_key:
            # We need to change key
            current_key = letter
            changes += 1

    return changes


def main():
    # Convert input into integers
    result = key_changes(sys.argv[1])
    print(result)


if __name__ == '__main__':
    main()