Advertisement
Guest User

Untitled

a guest
Jan 9th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.54 KB | None | 0 0
  1. '''
  2. author = kriplmrzak
  3. '''
  4. TEXTS = ['''
  5. Situated about 10 miles west of Kemmerer,
  6. Fossil Butte is a ruggedly impressive
  7. topographic feature that rises sharply
  8. some 1000 feet above Twin Creek Valley
  9. to an elevation of more than 7500 feet
  10. above sea level. The butte is located just
  11. north of US 30N and the Union Pacific Railroad,
  12. which traverse the valley. ''',
  13.  
  14.          '''At the base of Fossil Butte are the bright
  15. red, purple, yellow and gray beds of the Wasatch
  16. Formation. Eroded portions of these horizontal
  17. beds slope gradually upward from the valley floor
  18. and steepen abruptly. Overlying them and extending
  19. to the top of the butte are the much steeper
  20. buff-to-white beds of the Green River Formation,
  21. which are about 300 feet thick.''',
  22.  
  23.          '''The monument contains 8198 acres and protects
  24. a portion of the largest deposit of freshwater fish
  25. fossils in the world. The richest fossil fish deposits
  26. are found in multiple limestone layers, which lie some
  27. 100 feet below the top of the butte. The fossils
  28. represent several varieties of perch, as well as
  29. other freshwater genera and herring similar to those
  30. in modern oceans. Other fish such as paddlefish,
  31. garpike and stingray are also present.'''
  32.          ]
  33.  
  34. LOGINS = {
  35.     'bob': '123',
  36.     'ann': 'pass123',
  37.     'mike': 'password123',
  38.     'liz': 'pass123'
  39. }
  40.  
  41. ALLNUMERIC = 0
  42.  
  43.  
  44. def countAllWords(allWords):
  45.     """Return length of array from param.
  46.    """
  47.     return len(allWords)
  48.  
  49.  
  50. def capitalStart(allWords):
  51.     """Return length of array of capital words
  52.    created from param.
  53.    """
  54.     return len([word for word in allWords if word[0].isupper()])
  55.  
  56.  
  57. def upperWords(allWords):
  58.     """Return number of upper words from param.
  59.    Go through param array and create sum of lower words
  60.    and digit only words. If one of these arrays are
  61.    bigger then 0 word cannot be upper only.
  62.    """
  63.     num = 0
  64.     for word in allWords:
  65.         lowerCount = sum(map(str.islower, word))
  66.         digitCount = sum(map(str.isdigit, word))
  67.         if lowerCount == 0 and digitCount == 0:
  68.             num += 1
  69.     return num
  70.  
  71.  
  72. def lowerWords(allWords):
  73.     """Return number of lower words from param.
  74.    Go through param array and create sum of upper words
  75.    and digit only words. If one of these arrays are
  76.    bigger then 0 word cannot be upper only.
  77.    """
  78.     num = 0
  79.     for word in allWords:
  80.         upperCount = sum(map(str.isupper, word))
  81.         digitCount = sum(map(str.isdigit, word))
  82.         if upperCount == 0 and digitCount == 0:
  83.             num += 1
  84.     return num
  85.  
  86.  
  87. def numericWords(allWords):
  88.     """Return number of numeric words from param.
  89.    Go through param array and create sum of digit words
  90.    and if length of array is same as word its digit only.
  91.  
  92.    Also if word is digit it will count sum of all of them.
  93.    """
  94.     global ALLNUMERIC
  95.     num = 0
  96.     for word in allWords:
  97.         digitCount = sum(map(str.isdigit, word))
  98.         if digitCount == len(word):
  99.             # immidieatly count numeric values
  100.             ALLNUMERIC += int(word)
  101.             num += 1
  102.     return num
  103.  
  104.  
  105. def wordChart(allWords):
  106.     """Create chart based on number of words and length.
  107.    Run through param array and create dict like:
  108.        length : numberOfWords
  109.        1:5 , 5 words of length 1
  110.    Then sort them by key and print with *.
  111.    """
  112.     chart = {}
  113.     for word in allWords:
  114.         if len(word) in chart:
  115.             chart[len(word)] += 1
  116.         else:
  117.             chart[len(word)] = 1
  118.     sortedChart = sorted(chart.items())
  119.     for key, value in sortedChart:
  120.         print(str(key) + " " + value * "*" + " " + str(value))
  121.  
  122.  
  123. def allWords(textNumber):
  124.     """Return array of words from param text.
  125.    Strip all newlines, spaces and so on.
  126.    """
  127.     allWords = []
  128.     for word in TEXTS[textNumber].split((' ')):
  129.         if "\n" in word:
  130.             for x in word.replace(',', '').replace('.', '').split('\n'):
  131.                 if x != '':
  132.                     allWords.append(x)
  133.         else:
  134.             if word != '':
  135.                 allWords.append(word.replace('.', ''))
  136.     return allWords
  137.  
  138.  
  139. def checkLogin():
  140.     """Return True,False based on given credentials.
  141.    Check with hardcoded login:pw variable LOGINS.
  142.    """
  143.     user = input("Username: ")
  144.     password = input("Password: ")
  145.     if user in LOGINS and password == LOGINS[user]:
  146.         return True
  147.     return False
  148.  
  149.  
  150. if __name__ == "__main__":
  151.     """Main, say hello then check login pick number,
  152.    test if number is in given length of TEXT variable.
  153.    Then call all defind functions.
  154.    """
  155.     print("Hello nigger!")
  156.     listToCheck = list(range(0, len(TEXTS)))
  157.     while checkLogin():
  158.         textNumber = int(input("Select TEXT number 1-" +
  159.                                str(len(TEXTS)) + ": ")) - 1
  160.         if textNumber not in listToCheck:
  161.             print("Wrong text number got only 1-" + str(len(TEXTS)))
  162.             exit(1)
  163.         allWords = allWords(textNumber)
  164.         print(allWords)
  165.         print("Number of words in total: " + str(countAllWords(allWords)))
  166.         print("Number of words starting with capital: " +
  167.               str(capitalStart(allWords)))
  168.         print("Number of uppercase words: " + str(upperWords(allWords)))
  169.         print("Number of lowercase words: " + str(lowerWords(allWords)))
  170.         print("Number of numeric-only words: " + str(numericWords(allWords)))
  171.         wordChart(allWords)
  172.         print("Sum of all numeric words: " + str(ALLNUMERIC))
  173.     else:
  174.         print("Wrong USER or PASSWORD")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement