From add8d7fd4eb2ad39bd4e70bc0f2566b3d5528f21 Mon Sep 17 00:00:00 2001 From: Simon Green Date: Sun, 18 Aug 2024 21:27:02 +1000 Subject: sgreen solutions to challenge 282 --- challenge-282/sgreen/python/ch-2.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 challenge-282/sgreen/python/ch-2.py (limited to 'challenge-282/sgreen/python/ch-2.py') diff --git a/challenge-282/sgreen/python/ch-2.py b/challenge-282/sgreen/python/ch-2.py new file mode 100755 index 0000000000..4673e3aef7 --- /dev/null +++ b/challenge-282/sgreen/python/ch-2.py @@ -0,0 +1,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() -- cgit