# Habitica Programming Guild September 2018 # Challenge in Python # # Counts letters (total, upper and lower case) of sentence input by the user (symbols are not welcome but counted anyway :) # Since I've never done something in Python before, I used https://py-tutorial-de.readthedocs.io/de/python-3.3 and https://www.python-kurs.eu as reference. # Used this one for online debugging: https://www.onlinegdb.com/online_python_compiler # And because I forgot the ascii numbers of the letters I used http://www.asciitable.com/ # Cheers MetHorn def word_count(sentence): # function to count the letters lc_ucase, lc_lcase, junk = 0, 0, 0 # counter for upper case letters, lower case letters and junk (everything else) lbound_ucase, ubound_ucase = 65, 90 # ascii bound for ucase letters lbound_lcase, ubound_lcase = 97, 122 # ascii bound for ucase letters for i in range(len(sentence)): # loop over length of string letter = ord(sentence[i]) if (letter >= lbound_ucase) and (letter <= ubound_ucase): # if ucase letter lc_ucase = lc_ucase + 1 elif (letter >= lbound_lcase) and (letter <= ubound_lcase): # if lcase letter lc_lcase = lc_lcase + 1 else: # if junk junk = junk + 1 print("Your sentence contains:") print(str(lc_ucase) + " upper case letters") print(str(lc_lcase) + " lower case letters") tlc = lc_ucase + lc_lcase print(str(tlc) + " letters total") print(str(junk) + " other characters, junk and stuff") sin = str(input("Enter sentence: \n? ")) # getting input as string print("\nYou entered: " + sin) print(str(len(sin)) + " Characters.\nLets see...\n") word_count(sin) # counting letters by function print("\nBye")