COMM 337代写、代做python设计编程
- 首页 >> Python编程 COMM 337: Homework 2 DUE DATE: Oct 2, 2024 12:00pm
This is HW2 Python assignment. There are 13 problems. Each problem is 7 points and the total is 100 points (9 for following file/print format).
Instructions:
1. Late submissions will not be accepted.
2. Submit your Python code in UBC Canvas. DO NOT email your homework to TA or me.
3. Don’t submit the output txt file. I will run your Python code to generate it.
(Initial Setup) Create and download:
1. Create a new python notebook for this homework and download the “last.txt” file into the same directory, where your notebook is located.
Write your Python code in your notebook file for Problems 2 to 20.
2. Open “last.txt” file with “read-only” file mode.
3. Find the number of characters in the file and assign it to “ans3”
variable.
4. Find the number of words (including both numbers and names) in the
file and assign it to “ans4” variable.
5. Find the number of lines in the file and assign it to “ans5” variable.
6. Count the last names starting with “L” and assign it to “ans6” variable.
7. Count the last names ending with “E” and assign it to “ans7” variable.
8. Count the last names with length 3 and assign it to “ans8” variable.
9. Count the numbers larger than 0.1 and assign it to “ans9” variable.
10. Count the numbers smaller than 0.02 and assign it “ans10”
variable.
11. Get the number next to your last name and assign it to “ans11”
variable. If your last name doesn’t appear, “ans11” should be 0. 12. Find the last name that comes last in the dictionary order and
assign it to “ans12” variable.
13. Find the last name that comes first in the dictionary order and
assign it to “ans13” variable.
14. Find the longest last name and assign it to “ans14” variable.
15. Find the shortest last name and assign it to “ans15” variable.
(Note: don’t worry about the weird last name in the last.txt file. I put it
there intentionally.)
16. Create a new file “hw2_answers_STUDENTID_FIRST_LAST.txt” using
open() function with “write” mode, where FIRST and LAST should be
your first and last names. For example,
hw2_answers_1234_JANE_DOE.txt will be my output file.
17. Write your student id, first name, last name, and email address in
the first line of “hw2_answers_STUDENTID_FIRST_LAST.txt” file. 18. Write all your answers into the
“hw2_answers_STUDENTID_FIRST_LAST.txt” file. Each answer will take a line with “answerXX=YY” format. Use your ansXX variables. Don’t do hard coding by using the actual values.
19. Write “Homework 2 is done!!!” in the last line of “hw2_answers_STUDENTID_FIRST_LAST.txt” file.
20. Close “ hw2_answer_STUDENTID_FIRST_LAST.txt” file using close() method.
Submission:
21. Export your file as a .py file and submit it to Canvas. Please DO NOT submit your .ipynb file. Also, make sure you EXPORT the file from jupyter and not just rename the file extension. You do NOT need to submit your generated output text file.
Your output text file should look like this:
1234 Jane Doe jane.doe@sauder.ubc.ca
answer3=XX
answer4=XX
answer5=XX
answer6=XX
answer7=XX
answer8=XX
answer9=XX
answer10=XX
answer11=XX
answer12=XX
answer13=XX
answer14=XX
answer15=XX
Homework 2 is done!!!
This is HW2 Python assignment. There are 13 problems. Each problem is 7 points and the total is 100 points (9 for following file/print format).
Instructions:
1. Late submissions will not be accepted.
2. Submit your Python code in UBC Canvas. DO NOT email your homework to TA or me.
3. Don’t submit the output txt file. I will run your Python code to generate it.
(Initial Setup) Create and download:
1. Create a new python notebook for this homework and download the “last.txt” file into the same directory, where your notebook is located.
Write your Python code in your notebook file for Problems 2 to 20.
2. Open “last.txt” file with “read-only” file mode.
3. Find the number of characters in the file and assign it to “ans3”
variable.
4. Find the number of words (including both numbers and names) in the
file and assign it to “ans4” variable.
5. Find the number of lines in the file and assign it to “ans5” variable.
6. Count the last names starting with “L” and assign it to “ans6” variable.
7. Count the last names ending with “E” and assign it to “ans7” variable.
8. Count the last names with length 3 and assign it to “ans8” variable.
9. Count the numbers larger than 0.1 and assign it to “ans9” variable.
10. Count the numbers smaller than 0.02 and assign it “ans10”
variable.
11. Get the number next to your last name and assign it to “ans11”
variable. If your last name doesn’t appear, “ans11” should be 0. 12. Find the last name that comes last in the dictionary order and
assign it to “ans12” variable.
13. Find the last name that comes first in the dictionary order and
assign it to “ans13” variable.
14. Find the longest last name and assign it to “ans14” variable.
15. Find the shortest last name and assign it to “ans15” variable.
(Note: don’t worry about the weird last name in the last.txt file. I put it
there intentionally.)
16. Create a new file “hw2_answers_STUDENTID_FIRST_LAST.txt” using
open() function with “write” mode, where FIRST and LAST should be
your first and last names. For example,
hw2_answers_1234_JANE_DOE.txt will be my output file.
17. Write your student id, first name, last name, and email address in
the first line of “hw2_answers_STUDENTID_FIRST_LAST.txt” file. 18. Write all your answers into the
“hw2_answers_STUDENTID_FIRST_LAST.txt” file. Each answer will take a line with “answerXX=YY” format. Use your ansXX variables. Don’t do hard coding by using the actual values.
19. Write “Homework 2 is done!!!” in the last line of “hw2_answers_STUDENTID_FIRST_LAST.txt” file.
20. Close “ hw2_answer_STUDENTID_FIRST_LAST.txt” file using close() method.
Submission:
21. Export your file as a .py file and submit it to Canvas. Please DO NOT submit your .ipynb file. Also, make sure you EXPORT the file from jupyter and not just rename the file extension. You do NOT need to submit your generated output text file.
Your output text file should look like this:
1234 Jane Doe jane.doe@sauder.ubc.ca
answer3=XX
answer4=XX
answer5=XX
answer6=XX
answer7=XX
answer8=XX
answer9=XX
answer10=XX
answer11=XX
answer12=XX
answer13=XX
answer14=XX
answer15=XX
Homework 2 is done!!!