Finding The Python Solutions Question And Answers Hi, there are 6 easy python programing question, please follow the instruction, Thank you Q2
1 Point
Write a function named avg that fulfills the following specification by replacing the pass line:
def avg (numbers) :
NH
signature: list (float) -> float
precondition: numbers != []
returns the average (mean) of a non-empty list of floats
pass # TODO: implement the body of this function
You may assume that the input is not an empty list. That is, your code does not need to handle
the situation when numbers is []. Your function should not use print or input at all.
Note: for the purposes of this problem, you may not use the built-in sum function, rather
you should write a loop that iterates over the items in the list.
Please select file(s)
Select file(s)
Q3
1 Point
Write a function named sum_some ( num1, num2, 1st) with three parameters: lower, upper and
numbers, that returns the sum of the elements of the list numbers which are between lower and
upper (inclusive). If the list numbers is empty then your function should return O. Your
function should take 2 integers and a list and returns an integer.
For example:
>>> sum_some (0, 100, [])
0
>>> sum_some (0, 100,[1,2,3,4,5])
15
>>> sum_some (2 4 [1,2,3,4,5))
9
>>> sum_some (3, 3 , [2,2,3,3,4,4])
6
Your function should not use print or input at all.
Please select file(s)
Select file(s)
Q4
1 Point
Write a function my_count(1st, val) that takes a list of integers, Ist, and an integer, val, and
returns the
number of times that val occurs in Ist. If val does not appear in Ist, the function should return O.
Don’t make a call to the list method count() in your function. Instead, you should think about
how the count method might be implemented and how to recreate that functionality.
The function signature is given below:
def my_count(lst,val):
# sig : list (int), int -> int
For example, a call to my_count([7,2,1,3,7,9), 7) would return 2 and a call to
my_count([4,6,1,2], 3) would return 0.
Please select file(s)
Select file(s)
Q5
2 Points
Write a function named is_sorted(1st) that takes a list of numbers and returns True in case
the list is in increasing order, and False otherwise.
This means that every number in the list should be larger or the same as the preceding number.
By convention, we will return True for the empty list.
For example:
>>> is_sorted (1)
True
>>> is_sorted ([1])
True
>>> is_sorted ([1, 2
True
>>> is_sorted ([1, 2,2
True
>>> is_sorted ([1 2 2
False
3])
3])
1
11)
Hint: notice that a list is sorted just in case there is no adjacent pair of entries that is out of
order. In other words, a list is sorted if for every adjacent pair of entries, the one on the left is
less than or equal to the one on the right.
Note: for the purposes of this problem, you may not use any of Python’s built-in sorting
functions, instead, you should traverse the list and check that all adjacent pairs of entries are
ordered.
Your function should not use print or input at all.
Please select file(s)
Select file(s)
Q6
2 Points
Write a function get_common_elems (Isti, Ist2) that takes two lists of integers, Ist1, and Ist2,
and returns a new list containing the elements in common between the two lists. You can
assume that there are no
repeated elements in the lists. Also, the ordering of the elements in the returned new list is not
significant
The function signature is given below:
def get_common_elems(1sti, 1st2):
sig : list (int),list (int) -> list(int)
For example, a call to get_common_elems (15,1,4,3,6],[6,1,8,3]) will return the list 1, 3, 6.
Hint: Think about how you can make use of the in operator. You only need to iterate over one of
the lists.
Please select file(s)
Select file(s)
Submit Answer
Purchase answer to see full
attachment
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.