Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- author = kriplmrzak
- '''
- TEXTS = ['''
- Situated about 10 miles west of Kemmerer,
- Fossil Butte is a ruggedly impressive
- topographic feature that rises sharply
- some 1000 feet above Twin Creek Valley
- to an elevation of more than 7500 feet
- above sea level. The butte is located just
- north of US 30N and the Union Pacific Railroad,
- which traverse the valley. ''',
- '''At the base of Fossil Butte are the bright
- red, purple, yellow and gray beds of the Wasatch
- Formation. Eroded portions of these horizontal
- beds slope gradually upward from the valley floor
- and steepen abruptly. Overlying them and extending
- to the top of the butte are the much steeper
- buff-to-white beds of the Green River Formation,
- which are about 300 feet thick.''',
- '''The monument contains 8198 acres and protects
- a portion of the largest deposit of freshwater fish
- fossils in the world. The richest fossil fish deposits
- are found in multiple limestone layers, which lie some
- 100 feet below the top of the butte. The fossils
- represent several varieties of perch, as well as
- other freshwater genera and herring similar to those
- in modern oceans. Other fish such as paddlefish,
- garpike and stingray are also present.'''
- ]
- LOGINS = {
- 'bob': '123',
- 'ann': 'pass123',
- 'mike': 'password123',
- 'liz': 'pass123'
- }
- ALLNUMERIC = 0
- def countAllWords(allWords):
- """Return length of array from param.
- """
- return len(allWords)
- def capitalStart(allWords):
- """Return length of array of capital words
- created from param.
- """
- return len([word for word in allWords if word[0].isupper()])
- def upperWords(allWords):
- """Return number of upper words from param.
- Go through param array and create sum of lower words
- and digit only words. If one of these arrays are
- bigger then 0 word cannot be upper only.
- """
- num = 0
- for word in allWords:
- lowerCount = sum(map(str.islower, word))
- digitCount = sum(map(str.isdigit, word))
- if lowerCount == 0 and digitCount == 0:
- num += 1
- return num
- def lowerWords(allWords):
- """Return number of lower words from param.
- Go through param array and create sum of upper words
- and digit only words. If one of these arrays are
- bigger then 0 word cannot be upper only.
- """
- num = 0
- for word in allWords:
- upperCount = sum(map(str.isupper, word))
- digitCount = sum(map(str.isdigit, word))
- if upperCount == 0 and digitCount == 0:
- num += 1
- return num
- def numericWords(allWords):
- """Return number of numeric words from param.
- Go through param array and create sum of digit words
- and if length of array is same as word its digit only.
- Also if word is digit it will count sum of all of them.
- """
- global ALLNUMERIC
- num = 0
- for word in allWords:
- digitCount = sum(map(str.isdigit, word))
- if digitCount == len(word):
- # immidieatly count numeric values
- ALLNUMERIC += int(word)
- num += 1
- return num
- def wordChart(allWords):
- """Create chart based on number of words and length.
- Run through param array and create dict like:
- length : numberOfWords
- 1:5 , 5 words of length 1
- Then sort them by key and print with *.
- """
- chart = {}
- for word in allWords:
- if len(word) in chart:
- chart[len(word)] += 1
- else:
- chart[len(word)] = 1
- sortedChart = sorted(chart.items())
- for key, value in sortedChart:
- print(str(key) + " " + value * "*" + " " + str(value))
- def allWords(textNumber):
- """Return array of words from param text.
- Strip all newlines, spaces and so on.
- """
- allWords = []
- for word in TEXTS[textNumber].split((' ')):
- if "\n" in word:
- for x in word.replace(',', '').replace('.', '').split('\n'):
- if x != '':
- allWords.append(x)
- else:
- if word != '':
- allWords.append(word.replace('.', ''))
- return allWords
- def checkLogin():
- """Return True,False based on given credentials.
- Check with hardcoded login:pw variable LOGINS.
- """
- user = input("Username: ")
- password = input("Password: ")
- if user in LOGINS and password == LOGINS[user]:
- return True
- return False
- if __name__ == "__main__":
- """Main, say hello then check login pick number,
- test if number is in given length of TEXT variable.
- Then call all defind functions.
- """
- print("Hello nigger!")
- listToCheck = list(range(0, len(TEXTS)))
- while checkLogin():
- textNumber = int(input("Select TEXT number 1-" +
- str(len(TEXTS)) + ": ")) - 1
- if textNumber not in listToCheck:
- print("Wrong text number got only 1-" + str(len(TEXTS)))
- exit(1)
- allWords = allWords(textNumber)
- print(allWords)
- print("Number of words in total: " + str(countAllWords(allWords)))
- print("Number of words starting with capital: " +
- str(capitalStart(allWords)))
- print("Number of uppercase words: " + str(upperWords(allWords)))
- print("Number of lowercase words: " + str(lowerWords(allWords)))
- print("Number of numeric-only words: " + str(numericWords(allWords)))
- wordChart(allWords)
- print("Sum of all numeric words: " + str(ALLNUMERIC))
- else:
- print("Wrong USER or PASSWORD")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement