Placeholder

Python Assignments Stats Read File and Sentence Generator

$25.00

Description

These projects must be done in the latest version of IDLE:
A group of statisticians at a local college has asked you to create a set of functions that compute the median and mode of a set of numbers, as defined in Section 5.4. Define these functions in a module named stats.py. Also include a function named mean, which computes the average of a set of numbers. Each function should expect a list of numbers as an argument and return a single number. Each function should return 0 if the list is empty. Include a main function that tests the three statistical functions with a given list.
Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program quits. Otherwise, the program prints the line associated with that number.
Modify the sentence-generator program of Case Study 5.3 (Link Here: Fundamentals of Python: First Programs) so that it inputs its vocabulary from a set of text files at startup. The filenames are nouns.txt, verbs.txt, articles.txt, and prepositions.txt. (Hint: Define a single new function, getWords. This function should expect a filename as an argument. The function should open an input file with this name, define a temporary list, read words from the file, and add them to the list. The function should then convert the list to a tuple and return this tuple. Call the function with an actual filename to initialize each of the four variables for the vocabulary.)
SCREENSHOTS
SOLUTION
PAYMENT
The solution includes three python programs
Attachments [Move over files to preview content of those files]
Solution.zip (2.53 KB)
articles.txt
Generator.py
input.txt
nouns.txt
prepositions.txt
Program2.py
Stats.py
verbs.txt
Preview articles.txt
a one some any
x xxx xxxx xxx
Preview Generator.py
xxx xxxxxxxxxx():
“””xxxxxx xxx xxxxxxx x xxxx xxxxxx.”””
xxxxxx xxxxxx.xxxxxx(xxxxx) + ” ” + xxxxxxxxxx() + ” ” + xxxxxxxxxxxxxxxxxxx()
def prepositionalPhrase(): “””Builds and returns a prepositional phrase.””” return random.choice(prepositions) + ” ” + nounPhrase()
def main(): nouns, verbs, articles, prepositions = getWords() print (nouns, verbs, articles, prepositions) number = int(input(“Enter the number of sentences: “)) for count in range(number): print (sentence())
def getWords():
x = xxxx(‘xxxxx.xxx’, ‘x’)
xxxxxxxx(x, xxxxx)
x.xxxxx()
x = xxxx(‘xxxxx.xxx’, ‘x’)
xxxxxxxx(x, xxxxx)
x.xxxxx()
Preview input.txt
Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file.
xxxxxx xxxx xxxxxxx xxxxx xxxx 1 xx xxx xxxxxx xx xxxxx xx xxx xxxx.
xx xxx xxxxx xx 0, xxx xxxxxxx xxxxx.
xxxxxxxxx, xxx xxxxxxx xxxxxx xxx xxxx xxxxxxxxxx xxxx xxxx xxxxxx.
xx xxxx xx xxxxxxx xxxx xxxxxxxxxx, xxx xxx xxxx xxxxx xxxx xxx xxxxxxx.
Preview nouns.txt
boy girl dog town car
xxx xxxx xxx xxxx xxx
Preview prepositions.txt
to from over under on
xx xxxx xxxx xxxxx xx
Preview Program2.py
xxxxxx xx
xxx xxxx():
xxxxxxxx = xxxxxxxx()
f = open(fileName,”r”)
lines = f.readlines() f.close()
print (“Filename: ” + fileName) print (“Lines: ” + str(len(lines))) # Counts the lines.
xxxxxxxxx = xxxxx(“xxxx xxx xxxx xx xxxx: “)
xx xxxxxxxxx == “0”:
xxxx()
xxxx:
xxxxx (xxxxx[xxx(xxxxxxxxx) – 1])
Preview Stats.py
xxxxxx xxx
xxx xxxx(xxxx):
xx xxx(xxxx) == 0:
xxxxxx 0
list.sort() total = 0 for number in list: total += number return total / len(list)
def mode(list): numberDictionary = {} for digit in list: number = numberDictionary.get(digit, None) if number == None: numberDictionary[digit] = 1
xxxx:
xxxxxxxxxxxxxxxx[xxxxx] = xxxxxx + 1
xxxxxxxx = xxx(xxxxxxxxxxxxxxxx.xxxxxx())
xxxxxxxx = []
xxx xxx xx xxxxxxxxxxxxxxxx:
xx xxxxxxxxxxxxxxxx[xxx] == xxxxxxxx:
Preview verbs.txt
sumped ran walked skipped
xxxxxx xxx xxxxxx xxxxxxx
Price: $25
Buy Now
Checkout
Added to cart
Add to Cart
Checkout
Added to cart
You May Also Like:
Python Assignments Caesar Cipher
Python Assignments Triangle and Guessing Number
Python Assignments Credit Plan and Series Numbers

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.