Placeholder

Fundamentals of Python Chapter 6 Project 6 7 8 9

$12.99

Description

These projects must be done in the latest version of IDLE:
6. Add a command to this chapter’s case study program that allows the user to view the contents of a file in the current working directory. When the command is selected, the program should display a list of filenames and a prompt for the name of the file to be viewed. Be sure to include error recovery.
7. Write a recursive function that expects a pathname as an argument. The pathname can be either the name of a file or the name of a directory. If the pathname refers to a file, its name is displayed, followed by its contents. Otherwise, if the pathname refers to a directory, the function is applied to each name in the directory. Test this function in a new program.
8. Lee has discovered what he thinks is a clever recursive strategy for printing the elements in a sequence (string, tuple, or list). He reasons that he can get at the first element in a sequence using the 0 index, and he can obtain a sequence of the rest of the elements by slicing from index 1. This strategy is realized in a function that expects just the sequence as an argument. If the sequence is not empty, the first element in the sequence is printed and then a recursive call is executed. On each recursive call, the sequence argument is sliced using the range 1:. Here is Lee’s function definition:
def printAll(seq):
if seq:
print seq[0]
printAll(seq[1:])
Write a script that tests this function and add code to trace the argument on each call. Does this function work as expected? If so, explain how it actually works, and describe any hidden costs in running it.
9. Write a program that computes and prints the average of the numbers in a text file. You should make use of two higher-order functions to simplify the design.
SCREENSHOTS
SOLUTION
PAYMENT
The solution includes four python programs
Attachments [Move over files to preview content of those files]
Fundamentals_of_Python_Chapter_6.zip (167.18 KB)
Fundamentals-of-Python-Chaper-6-Project-6-Screenshot.png
Fundamentals-of-Python-Chaper-6-Project-7-Screenshot.png
Fundamentals-of-Python-Chaper-6-Project-8-Screenshot.png
Fundamentals-of-Python-Chaper-6-Project-9-Screenshot.png
Python programs
numbers.txt
Project6.py
Project7.py
Project8.py
Project9.py
test
folder 1
file1.txt
file2.txt
folder 2
folder 3
Preview numbers.txt
1 2 4 5 7
7
9
100
Preview Project6.py
“””
xxxxxx xx, xx.xxxx
xxxx = ‘8’
xxxxxxxx = (‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’)
xxxx = “””1 xxxx xxx xxxxxxx xxxxxxxxx
2 Move up 3 Move down 4 Number of files in the directory 5 Size of the directory in bytes 6 Search for a filename 7 View a selected file 8 Quit the program”””
def main(): while True: print (os.getcwd()) print (MENU)
xxxxxxx = xxxxxxxxxxxxx()
xxxxxxxxxx(xxxxxxx)
xx xxxxxxx == xxxx:
xxxxx (“xxxx x xxxx xxx!”)
xxxxx
Preview Project7.py
##xxxxx x xxxxxxxxx xxxxxxxx xxxx xxxxxxx x xxxxxxxx xx xx xxxxxxxx. xxx
##xxxxxxxx xxx xx xxxxxx xxx xxxx xx x xxxx xx xxx xxxx xx x xxxxxxxxx. xx xxx
##xxxxxxxx xxxxxx xx x xxxx, xxx xxxx xx xxxxxxxxx, xxxxxxxx xx xxx xxxxxxxx.
##xxxxxxxxx, xx xxx xxxxxxxx xxxxxx xx x xxxxxxxxx, xxx xxxxxxxx xx xxxxxxx xx
##xxxx xxxx xx xxx xxxxxxxxx. xxxx xxxx xxxxxxxx xx x xxx xxxxxxx.
import os pos = []
def findFile(pathname): os.chdir(os.getcwd()+os.sep+pathname) print (os.getcwd())
xxxx = xx.xxxxxxx(xx.xxxxxx())
xxx xxxxxxx xx xxxx:
xx xx.xxxx.xxxxx(xxxxxxx) == xxxx:
xxx.xxxxxx(xx.xxxxxx())
xxxxxxxx(xxxxxxx)
xx.xxxxx(xxx.xxx())
Preview Project8.py
#xxx xxx xxxxxxxxxx xxxx xx xxxxxx xx x xxxxxx xxxxxxxxx xxxxxxxx xxx xxxxxxxx xxx xxxxxxxx xx x xxxxxxxx
# (xxxxxx, xxxxx, xx xxxx). xx xxxxxxx xxxx xx xxx xxx xx xxx xxxxx xxxxxxx xx x xxxxxxxx xxxxx xxx 0 xxxxx,
# xxx xx xxx xxxxxx x xxxxxxxx xx xxx xxxx xx xxx xxxxxxxx xx xxxxxxx xxxx xxxxx 1. xxxx xxxxxxxx xx xxxxxxxx
# xx x xxxxxxxx xxxx xxxxxxx xxxx xxx xxxxxxxx xx xx xxxxxxxx. xx xxx xxxxxxxx xx xxx xxxxx, xxx xxxxx xxxxxxx
# xx xxx xxxxxxxx xx xxxxxxx xxx xxxx x xxxxxxxxx xxxx xx xxxxxxxx. xx xxxx xxxxxxxxx xxxx, xxx xxxxxxxx xxxxxxxx
# is sliced using the range 1:. Here is Lee’s function definition: # def printAll(seq): # if seq: # print seq[0] # printAll(seq[1:]) # Write a script that tests this function and add code to trace the argument on each call. Does this function work as # expected? If so, explain how it actually works, and describe any hidden costs in running it.
xxx xxxxxxxx(xxx):
xx xxx:
xxxxx (xxx[0]) # xxxxx xxxxx xxxxxx
xxxxxxxx(xxx[1:]) # xxxxx xxxx xx xxxxxx xxx[1], xxx[2],….xxx[x]
Preview Project9.py
##xxxxx x xxxxxxx xxxx xxxxxxxx xxx xxxxxx xxx xxxxxxx xx xxx xxxxxxx xx
##x xxxx xxxx. xxx xxxxxx xxxx xxx xx xxx xxxxxx-xxxxx xxxxxxxxx xx xxxxxxxx
##xxx xxxxxx.
xxx xxx(xxx):
sum = 0 for i in num: sum += i return (sum / len(num))
def main(): file=input(“Enter a name of file which contains list of numbers: >> “)
xxx = []
xxxxx (“xxxx xx xxxxxxx:”)
xxxx xxxx(xxxx) xx x:
xxx xxxx xx x:
xxx.xxxxxx(xxxxx(xxxx))
xxxxx(xxxxx(xxxx))
Preview file1.txt
Preview file2.txt
Price: $25
Buy Now
Checkout
Added to cart
Buy More Save More
Buy at least TWO items & save up to 30% OFF your ENTIRE order!
Rack up instant rebates in your shopping cart. Simply add items to your cart, and see the savings add up.
Discounts will automatically be applied on eligible orders.
Fundamentals of Python Chapter 6 Project 6 – $7.00
Fundamentals of Python Chapter 6 Project 7 – $7.00
Fundamentals of Python Chapter 6 Project 8 – $7.00
Fundamentals of Python Chapter 6 Project 9 – $7.00
Add to Cart
Checkout
Added to cart
You May Also Like:
Fundamentals of Python Chapter 8 Project 1 2 3
Fundamentals of Python Chapter 9 Project 1 2

Reviews

There are no reviews yet.

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