Answer:
- def check_subset(l1, l2):
- status = False
- count = 0
- if(len(l1) > len(l2)):
- for x in l2:
- for y in l1:
- if x == y:
- count += 1
-
- if(count == len(l2)):
- return True
- else:
- return False
-
- else:
- for x in l1:
- for y in l2:
- if x==y:
- count += 1
-
- if(count == len(l1)):
- return True
- else:
- return False
-
- print(check_subset([1,4,6], [1,2,3,4,5,6]))
- print(check_subset([2,5,7,9,8], [7,8]))
- print(check_subset([1, 5, 7], [1,4,6,78,12]))
Explanation:
The key idea of this solution is to create a count variable to track the number of the elements in a shorter list whose value can be found in another longer list.
Firstly, we need to check which list is shorter (Line 4). If the list 2 is shorter, we need to traverse through the list 2 in an outer loop (Line 5) and then create another inner loop to traverse through the longer list 1 (Line 6). If the current x value from list 2 is matched any value in list 1, increment the count variable by 1. After finishing the outer loop and inner loop, we shall be able to get the total count of elements in list 2 which can also be found in list 1. If the count is equal to the length of list 2, it means all elements in the list 2 are found in the list 1 and therefore it is a subset of list 1 and return true (Line 10-11) otherwise return false.
The similar process is applied to the situation where the list 1 is shorter than list 2 (Line 15-24)
If we test our function using three pairs of input lists (Line 26-28), we shall get the output as follows:
True
True
False
27 mujeres
18 hombres
Mira:
60% * 45 = 2,700
2,700/100= 27
Si el 60% son mujeres, entonces
45-27=18 hombres
The sorted values array contains the sixteen integers 1, 2, 3, 13, 13, 20, 24, 25, 30, 32, 40, 45, 50, 52, 57, 60. How many recu
Licemer1 [7]
The number of recursive calls that have to be done using the binary search is 4.
<h3>How to do the recursive calls</h3>
binarySearch = (45, 0, 15)
start + end / 2 = value
mid = 0 + 15/2 = 7.5
The 7th element = 30
30 is less than 45
8 + 15/3
= 23/2 = 11.5
The 12th element = 52
52 is greater than 45
8 + 11/2
= 19/2 = 9.5
The value of 9 = 40 and 40 is less than 45
10+ 11/2 = 10.5
The tenth value is 45 hence the iteration to be done is 4.
Read more on binary here:
brainly.com/question/21475482
#SPJ1
Answer:
#here is function in python
#function that return integer if input can be converted to int
#if not it will return a string "Cannot converted!!"
def get_integer(inp):
try:
return int(inp)
except:
return "Cannot convert!!"
print()
#call the function with different inputs
print(get_integer("5"))
print(get_integer("Boggle."))
print(get_integer(5.1))
print()
Explanation:
Define a function get_integer() with a parameter.In this function there is try and except.First try will execute and if input can be converted to integer then it will convert it into integer and return it.If it will not able to convert the input into integer then except will return a string "Cannot convert!!".In the function get_integer(), there is no use of any conditionals or type function.
Output:
5
Cannot convert!!
5
Answer:
Check the explanation
Explanation:
A. The fundamental or basic operations are addition and division.
B. The total figure for each student (which starts at 0) will be included to c times. Given that there are r student totals, there are <em>r*c</em> additions for the totals. (An optional correct answer is <em>r*(c-1)</em> if you begin the accumulator with the initial item in a column, and perform <em>(c-1)</em> additions.)
Each exam average will be included to r times. In view of the fact that there are c exams, this gives another <em>c*r</em> additions.
All the exam average will be divided exactly once by the amount of students, c. So, c divisions.
C. <em>O(rc) </em>
D. LINEAR (Note: The Big O appears like a quadratic value, although the INPUT SIZE is rc, and the running time is linearly relative to the input size.)