Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This assignment is a programming exercise and you will need to create file called assignment 2 . py and upload it to Gradescope for grading.
This assignment is a programming exercise and you will need to create file called assignmentpy and upload it to Gradescope for grading. Each of the following tasks needs to be implemented as methods in the class Assignment You are free to implement other methods in the class andor use secondary py files for additional implementations. If you do so you will need to submit them to Gradescope as well.
Note that there are strict requirements how class and methods should be named. If you fail to follow the requirement, your work will not be graded. Each task is worth point.
You don't need to implement validation of the input parameters, we will always supply legitimate values in our testing scripts.
Make sure you implement each requested function as a class method! Unless it is explicitly asking for a static method, you must include self as a first special argument. For example, if asking to create a method foobar taking two arguments, you should write something like
class Assignment:
def foobarself firstargument, secondargument:
# body of the method
Task Constructor
Implement a constructor that accepts one parameter: year type int This parameter should initialize the similarly named class instance variable hint: these would start with self.
Task Age
Implement method named tellAge. This method should accept a single argument: currentYear type int
The result of this method should be printing on the standard output the following line:
Your age is XXXX
Where XXXX is calculated birth year, based on the supplied currentYear argument and year from the class instance variable.
Task List
Write a method named listAnniversaries that doesn't accepts arguments.
This method should return a list note unlike task not to print, but return a list! containing all year anniversaries, assuming today is year For example, when running the following code
a Assignment
ret alistAnniversaries
printret
The output should be
And when running the following:
a Assignment
ret alistAnniversaries
printret
The output should be
Task String Manipulation
Write a method named modifyYear with the following specification:
Input parameters:
variable named n type int: number to adjust list size
Return value should be a string, containing:
n times the first two characters in the text representation of the year eg if year and n then this part should be
odd positioned characters of text representation of year multiplied by n if year is and n then text representation is and you seelct odd characters, which is ; if year and n then text representation is and you select
For example,
a Assignment
ret amodifyYear
printret
should print
Task Loop and Conditional statements
Write a static method named checkGoodString with the following specification. Note that static methods don't have self but must be annotated with @staticmethod.
Input parameters:
variable named string, type str
Return Value:
type bool: True if string has the following requirements
Is at least characters long
Starts with lower case letter az
Contains only one number
For example,
ret AssignmentcheckGoodStringfobarmore"
printret
ret AssignmentcheckGoodStringfoobarmore"
printret
should print
False
True
Task Socket
Write a static method named connectTcp that will create TCP IPv socket AFINET, SOCKSTREAM connect to the specified hostport closes the connection, and returns True if the connection was established correctly.
Input parameters:
variable named host: type str
variable named port: type int
Return value
type bool: True if TCP connection successfully established, otherwise False
You can test this method with any Internet service, for example:
retval AssignmentconnectTcpwwwgoogle.com",
if retval:
printConnection established correctly"
else:
printSome error"
Note that Python by default will throw an exception if you trying to connect and connection cannot be established. You will need to handle this case to return False as required by this task.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started