Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMP1012 Assignment 2

Tips:

1.You can open this "ipynb"file using VSCode.You may need to download Jupyter extension.

2.You should read the requirements carefully and complete the codes in specific parts.You should not modify any other content except your codes.

3.Assignment2's deadline is October 20.Please submit your codes in time.No delay is allowed.

AutoGrading:

1.YOU MUST NAME YOUR NOTEBOOK USING ONLY YOUR  STUDENT  NUMBER(e.g., 24018121r.ipynb).OTHERWISE AUTOGRADING WILL NOT WORK.

2.You can only write your codes in the specific code cells and within a certain range.Write all the codes in a single function and return the final result.

3.You can not modify the function names and parameters.

4.You better not modify anything related to otter and grader.check(...).

5.You can test and print the results in the test cell when writing your assignment,but make sure that the solution code in the specific code cells does not contain any print statements.

6.Violating the above rules may lead to unpredictable results,such as a 0 mark.

Question 1(25pts)

Create a program with a function called compare_digit_sums(s).This function takes a string  s as its parameter.If s can be converted to a floating-point number,the function returns the integer part (int)of the number if the sum of the digits in the integer part is less than or equal to the sum of the digits in the fractional part.If the sum of the digits in the integer part is greater,it returns the fractional part.If s cannot be converted to a floating-point number,it returns "Invalid input".

Requirements

1.The functionality of the program and function should be correct.

2.You should implement the function compare_digit_sums.

Assumptions

1.We  assume  that  the  input  string  consists  solely  of  eleven  specific  characters:0,1,2, 3,4,5,6,7,8,9    and     .when    calling     the    function.Situations     involving    other

characters  in  s,such  as  a6  or  le5,are  not  considered.

Question2(25pts)

Design a function get_passenger_list.This function has three parameters:

·    existing_passengers   :it  is  a  list  representing  the  names  of  passengers  currently  on board.

·    boarding_passengers  :it  is  a  list  representing  the  names  of passengers  boarding  at  this station.

·alighting_passengers  :it  is  a  list  representing  the  names  of  passengers  alighting  at  this station.

It is used to predict the list of passengers on the train after it has passed through a station. Importantly,the function can be invoked without specifying values for the

boarding_passengers(or    alighting_passengers    )parameters     when    no    passengers    board (or alight)at a station.If a passenger in the alighting_passengers is not found in the

existing_passengers  ,the  function  returns   the  string  'Invalid  input'.Otherwise,it  returns   a list of passenger names on board,sorted in ascending order.

Question3(25pts)

Create   a   function   called   find_longest_word_length    . This function takes a paragraph as input  and  calculates  the   length  of  the   longest  word   in  the   paragraph.The  paragraph  will contain   only    letters(both   uppercase    and   lowercase)and    four    non-letter   characters:newline (\n),period(.),comma(,),and     space().These      characters      separate     words.The      function returns  the  length  of  the  longest  word.

Question4 (25pts)

Create a function find_parentheses.This function calculates the total number of parentheses pairs in an expression,regardless of the parentheses'nesting depth.The function takes a string parameter expression,which is an arithmetic expression containing numbers,operators(+,    一 , * , / ) ,and  parentheses((,)).The  function  returns  the  total number of matched parentheses pairs.If the expression contains unmatched parentheses (i.e.,more left parentheses(than right parentheses),or vice versa,or if a first right parentheses)appears before a left parentheses(),the function returns None.