- This homework tests your knowledge of File Handling and use of Lists data type.
- Adhere to the naming conventions discussed in class for variable names, program name and function names
- Use meaningful names for variables, functions etc
- If there are two words in the variable use first word lowercase and first letter of second word upper case i.e., firstName or underscore between 2 words i.e first_name
- Include appropriate comments in the code
- Output should be displayed similar to as mentioned against each problem
- Indent the lines of code appropriately
1. Write and read file
a ) write_num.py (30 points)
Create a num_list file to write a range of numbers from 1 through 101.
Hints:
Define main ():
Open a file named as num_list in write mode.
Use for loop to write a range of numbers from 1 through 101 into the file.
Close file
b)read_num.py (40 points)
Use num_list file which got created in number 1.a. Write a program that will prompt the user to enter the name of the file (i.e. num_list.text), and display the first 10 lines of the file’s content. Use try/except construct to capture any file opening related errors such as invalid file name etc.
Hints:
Define main ():
Declare variables: line and counter, and initialize them
Prompt for file name: use input function
Open the file in read mode.
Read the lines in the file with readline function: ‘inline.readline()’ and initialize counter to 1
Use a while loop to read and display the first 10 lines
Use rstrip method to remove n characters at the end of the line
Print the line
Update the counter when the line is read
Close file
Expected output:
Enter the name of the file: filename.txt
#
#
#
#
#
#
#
#
2. numanalysis.py (30 points)
Write a program that asks user to enter a series of 10 numbers. The program should store the numbers in a list then display the following data.
1. The list contents
2. The lowest number in the list
3. The highest number in the list
4. The total of the number in the list
5. The average of the number in the list
Hints:
Define main ():
Declare variables and initialize them
Create an empty list
Use the for loop with the range function to loop through 10 numbers.
Prompt the User to enter the numbers from 1- 10.
Ex: Enter number 1 of 10:
Use append function to populate the list
Use min, max, sum, functions to find the low , high and total number of the list.
Ex: low = min(number_list)
Print the list contents
Print Low, high , total and average numbers of the list.
Expected output :
List: [#, #, #, #, #, #, #, #, #, #]
Low: #.##
High: #.##
Total: #.##
Average: #.##
We are a professional custom writing website. If you have searched a question
and bumped into our website just know you are in the right place to get help in your coursework.
Yes. We have posted over our previous orders to display our experience. Since
we have done this question before, we can also do it for you. To make sure we do
it perfectly, please fill our Order Form. Filling the order form correctly will assist
our team in referencing, specifications and future communication.
1. Click on the “Place order tab at the top menu or “Order Now” icon at the
bottom and a new page will appear with an order form to be filled.
2. Fill in your paper’s requirements in the “PAPER INFORMATION” section
and click “PRICE CALCULATION” at the bottom to calculate your order
price.
3. Fill in your paper’s academic level, deadline and the required number of
pages from the drop-down menus.
4. Click “FINAL STEP” to enter your registration details and get an account
with us for record keeping and then, click on “PROCEED TO CHECKOUT”
at the bottom of the page.
5. From there, the payment sections will show, follow the guided payment
process and your order will be available for our writing team to work on it.
The post This homework tests your knowledge of File Handl – Essayde Paper Writing Website appeared first on Student SCH.