预定/报价
University of Sydney Introduction to Programming COMP9001作业代写
叶师傅2024-05-09 14:12:33

input_parser.py

Python代写  do not hesitate to contact me!
WeChat:lovexc60

from emitter import Emitter

from receiver import Receiver

from mirror import Mirror

 

'''

Name:   

SID:    

Unikey:

 

input_parser - A module that parses the inputs of the program.

We define parsing as checking the validity of what has been entered

to determine if it's valid. If it's not valid, an appropriate message

should be printed. Whenever we retrieve input in the program, we

should be using functions from this module to validate it.

 

You are free to add more functions, as long as you aren't modifying the

existing scaffold.

'''

 

 

def parse_size(user_input: str) -> tuple[int, int] | None:

    # only requires implementation once you reach GET-MY-INPUTS

    '''

    Checks if user_input is a valid input for the size of the circuit board by

    performing the following checks:

      1)  user_input contains exactly 2 tokens. If there are 2 tokens, we

          interpret the first token as width and the second token as height for

          the remaining checks.

      2)  width is an integer.

      3)  height is an integer.

      4)  width is greater than zero.

      5)  height is greater than zero.

 

    Parameters

    ----------

    user_input - the user input for the circuit's board size

 

    Returns

    -------

    If all checks pass, returns a tuple containing the width and height of

    the circuit board.

    Else, if at any point a check fails, prints an error message stating the cause

    of the error and returns None, skipping any further checks.

 

    Example 1:

    >>> size = parse_size('18 0')

    Error: height must be greater than zero

    >>> size

    None

 

    Example 2:

    >>> size = parse_size('18 6')

    >>> size

    (18, 6)

    '''