Starting from:

$30

COMP1007 Assignment 2 Solved

1.     Develop a Python function that takes a year as an argument, and returns True if that year is a leap year, or False otherwise. You can assume the argument is always a positive integer. Save your source file as problem1.py.

2.     Develop a function that takes a year as an argument, and returns a dictionary that includes 12 key‐value pairs where the key is the name of a month (i.e., “January”, “February”, …, “December”) and the value is the number of days in that month. You can use the function in Problem 1 to determine the number of days in February (by import statement). Execute the function to obtain the dictionary for Year 2019, and then write a for loop to output the month names together with the number of days per month. Your output should look like the followings:

Year 2019:

January 31

February 28

March 31



 
Save your source file as problem2.py.

3.     Develop a Python program that displays the following shape on the screen as an animation. Your program should sleep for a second after showing each #. Save your source file as problem3.py.

 
 
 
 
 
 
 
#
 
 
 
 
 
 
#
#
 
 
 
 
 
#
#
#
 
 
 
 
#
#
#
#
 
 
 
#
#
#
#
#
 
 
#
#
#
#
#
#
 
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
 

4.     Develop a Python function that takes a positive integer as an argument and checks whether the argument is a prime number or not. The function should return True if the argument is a prime number, and False otherwise. You can use the simple Trial Division method described at

https://en.wikipedia.org/wiki/Prime_number#Trial_division to implement your function. Save your source file as problem4.py.

5.     Develop a Python function that takes a positive integer as an argument, and then returns a list that includes all prime numbers which are less than or equal to the argument. You can make use of the function developed in Problem 4.  For example, if the argument is 10, your function should return a list of [2, 3, 5, 7]. Save your source file as problem5.py.

 

 

More products