Www.just.edu.jo



This assignment is designed to help you better understand lists and user-defined functions. This one is similar in style to the previous homework, as before, there is a table that challenges you to evaluate some python expressions. Submission: You must put all your work in one Folder named based on your Name and ID. Then compress this folder into one .rar or .zip file and upload your compressed file into your account on the JUST e-learning system. Requirements:[4 Points] Write a python script named “q1.py” to evaluate all of the following expressions. Then fill the following table (submit both your q1.py and the Table below): Assume that alist = ['H','e','l','l','o',' ','W','o','r','l','d','!']ExpressionResultalist.remove('o')print(alist)alist.remove('x')pos = alist.index('o')print(pos)pos = alist.index('B')alist[0] = 'J'print(alist)alist.insert(4,'o')print(alist)s = alist[:]print(s)s[0] = 'C'print(s)print(alist)a = '-'.join(s)print(a)a = ''.join(s)print(a)t = list(a)print(t)[2 Points] write a python function that takes a list and a value and returns the number of elements in the list that are strictly less than value?Note:Save your solution in a script named q2.py Example: F2([5, 9, 1, 7], 6) evaluates to 2Precondition: alist is a list of intsPrecondition: value is an intPostcondition: a value that is >= 0[2 Points] Write a python function that takes a list and returns the number of unique elements in the list.Note: Save your solution in a script named q3.pyExample: F3([5, 9, 5, 7]) evaluates to 3Example: F3([5, 5, 1, 'a', 5, 'a']) evaluates to 3[2 Points] Write a python function that takes a list, max-value, and min-value and returns nothing . It alters and modifies the given list based on the max and min values. The resulting list is modified so that every element is between min and max.Modification Policy: Any number in the list less than min is replaced with min. Any number in the list greater than max is replaced with max. Any number between min and max is left unchanged.Note:this is a PROCEDURE; it modifies the list, but does not return a new list.Save your solution in a script named q4.pyExample: if alist is [-1, 1, 3, 5], then F4(thelist,0,4) changes alist to have [0,1,3,4] as its contents.Precondition: alist is a list of numbers (float or int)Precondition: min <= max is a numberPrecondition: max >= min is a number ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download