A dating website asks 100 users to pick their favourite romantic word.
It will count the number of times love is entered, the number of times flowers is entered and the number of times sunset is entered.
It will also count the number of time any other word is entered. For example, if the following words are entered:
then the results will be:
| love | flowers | sunset | other |
|---|---|---|---|
| 3 | 2 | 0 | 5 |
A programmer has started to write the program by designing functions to perform specific tasks:
def updateLoveCount():
#increment loveCount
def updateFlowerCount():
#increment flowerCount
def updateSunsetCount():
#increment sunsetCount
def updateOtherCount():
#increment otherCount
def evaluateWord():
#if the word is love, call updateLoveCount
#elif the word is flower, call updateFlowerCount
#elif the word is flower, call updateFlowerCount
#elif the word is sunset, call updateSunsetCount
#else call updateOtherCount
def displayFinalCounts():
#display the final count info
def main():
for i in range(100):
global word
word = input("Enter a word!")
evaluateWord()
displayFinalCounts()
#call main
main()
A language statistician asks users to enter 20 words into a computer program. The program counts how many of the words are longer than 7 characters.
If the final count is greater than 10, a message You have an impressive vocabulary! is displayed. Otherwise, a message Thank you for participating. is displayed.
A computer program generates 2 random numbers in the range 1 to 10.
Every time the 2 numbers are the same, a score is incremented by 1.
The process is repeated 10,000 times and the final result is displayed.
Write this program.