联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> CS作业CS作业

日期:2024-05-11 04:14

CP164 Data Structures and Algorithms

Lab Exercise 01 – Review of CP104

Objectives:

•    Practice CP104 Skills

•    Introduction to the mechanics and practices of the CP164 labs.

Lab Tasks

1.  Write afunction near_and_far() that accepts three intsa, b, and cas arguments. Return True if one of b or c is "close" (differing from a by at most 1), while the other is "far", differing from both other values by 2 or more.

2.  Write a function sum_without_twenties(a, b, c) that returns the sum of three int arguments a, b, and c. However, do not include any int as part of the sum if it is within the range [20, 29] (inclusive) .

3.   Write  a  function  sumDigits(n),  that  computes  the  sum  of the  digits  in  an  integer.  For  example, sumDigits(234) returns 9 (Hint: Use the % operator to extract digits, and the // operator to remove the extracted digit. For instance, to extract 4 from 234, use 234 % 10 To remove 4 from 234, use 234 // 10 Use a loop to repeatedly extract and remove the digits until all the digits are extracted.) Write a test program that prompts the user to enter an integer and displays the sum of all its digits.

4.  Write afunction get_substring_positions() that accepts two strings as arguments. Return the number of the positions where they contain the same substring of length 2. For example, "docatzz" and "dobatz" should yield 3, since the "do", "at", and "tz" substrings appear in the same place in both strings.

5.  Create  a  function  named filter_words()  which  accepts  two parameters: the filename and a list  of unwanted words. The function's purpose is to retrieve the content of the file without altering the original file or generating a new one. Instead, it will read the file, process its contents, and return a list containing the words from the original file, excluding any instances of the undesirable words. For example, if the input file named “best_essay.txt” contained these 4 lines:

like happy like birthday

yep summer is totally here

lol happy summer

and you had this list of words:

words_to_remove = ['like', 'whatever', 'lol', 'yep', 'totally']

The function call:

filter_words("best_essay.txt", words_to_remove)

would return this single list:

["happy", "birthday", "summer", "is", "here", "happy", "summer"]

You may assume that the input file contains no punctuation and all words in the input file and in the list words_to_remove are in lowercase.

6.  Create a function add_by_column() that takes a matrix as input and adds up each column, providing the resulting sum as output?

Submission Instructions

•     The deadline for lab submission is every Saturday 11:59pm.

•    The first 2 questions must be completed and graded during lab hours.

•    Put your name, ID, and Laurier email address in the comments section of all modules.

•    Export your completed project to a archive file named: login_lab00.zip. Use only Eclipse's built- in archive capability to create these .zip files. We strongly suggest you save this zip file to your

Downloads folder to make it easy to find.

•    Upload your completed project to the appropriate Dropbox inMoodle.

•    Lab code must not have any errors, unused imports, or warnings. Grading fails when it runs into errors or bad imports.

•    Lab code must have appropriate comments where required, explaining what each line of code does.

•    Marks are deducted from any tasks where these requirements are not met.

•    If you have problems creating, exporting, or renaming projects, follow the instructions inUsing Eclipse with PyDevtutorial.

•    Login_lab00.zip |

|       Question_ 1.py

|       Question_2.py

|       Question_3.py

|       Question_4.py

|       Question_5.py




版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp