Skip to content

Instantly share code, notes, and snippets.

@yuheiomori
Created August 14, 2014 08:40
Show Gist options
  • Save yuheiomori/a77a3c2b28f01304aaf8 to your computer and use it in GitHub Desktop.
Save yuheiomori/a77a3c2b28f01304aaf8 to your computer and use it in GitHub Desktop.
Lettercase Percentage Ratio (CodeEval) in Python 3.x
# coding=utf-8
import sys
def main():
with open(sys.argv[1], "r") as f:
for line in f:
lower_count = 0
upper_count = 0
for c in line.rstrip():
if c.islower():
lower_count += 1
else:
upper_count += 1
total_count = float(lower_count + upper_count)
lower_ratio = round((float(lower_count) / total_count) * 100.0, 2)
upper_ratio = round((float(upper_count) / total_count) * 100.0, 2)
print("lowercase: {lower_ratio:2.2f} uppercase: {upper_ratio:2.2f}".format(
lower_ratio=lower_ratio,
upper_ratio=upper_ratio))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment