
test cases
cannibal([27, 9, 3, 8, 11], 11) == 2
cannibal([27, 9, 3, 8, 11], 50) == 0
cannibal([3, 3, 3, 2, 2, 2, 1, 1, 1], 4) == 9
cannibal("1,2,3,4,5", 5) == 4
Hello, please comment if there is any more requirement from the question. I will be happy to help. Please give a thumbs up if the solution helped you.
Answer:
I think the third test case is wrong.
Please use tabs properly as python is sensitive to tabs. Thanks.
Hi, I think that the third test case is incorrect. Can you please recheck once.
from sys import stdin
def cannibal(numbers, query):
count =0
for n in numbers:
if n>=query:
count=count+1
cannibals, available = 0, len(numbers)
sortedNumbers = sorted(numbers)
sortedNumbers.reverse()
print(sortedNumbers)
i =0
while i< len(numbers):
tempNumber=sortedNumbers[i]
j = len(numbers)-1
while j>=0:
if i==j:
j=j-1
continue
if
tempNumber>sortedNumbers[j]:
tempNumber=tempNumber+1
sortedNumbers[j]=None
if tempNumber==query:
count=count+1
break
j=j-1
i=i+1
return count;
print(cannibal([27, 9, 3, 8, 11], 11))
print(cannibal([27, 9, 3, 8, 11], 50))
test cases cannibal([27, 9, 3, 8, 11], 11) == 2 cannibal([27, 9, 3, 8, 11], 50)...
PYTHON REQUIRED
Bonus (4 points): Why was 6 afraid of 7? Because 7 89! Actually, this is mathematically impossible. "Cannibal numbers" as they're called can only eat numbers that are smaller than them, or the same size. After eating another number, the number that gets eaten disappears, and the number that ate them increases by 1 For example, given the following set of numbers, let's pretend that 9 is the cannibal. 127, 9,3, 8, 11] 9 could start by eating...
1. use python List to Dictionary Write a function that has three parameters: a list of unsorted numbers with no duplicates, a start number, and an end number. This function should return a dictionary with all integers between the start and end number (inclusive) as the keys and their respective indices in the list as the value. If the integer is not in the list, the corresponding value would be None. Example unsorted list: [2,1,10,0,4,3] two numbers: 3, 10 returned...
The experimenter examines thought processes and had 10 kids eat as many lollipops as they could in ten minutes. Group 1 was told that this tested innate eating ability, group 2 was told this was a task to fill time. Data: Innate eating ability: 4, 7,6, 5, 8, Time-filling eating ability: 8, 9,11, 5, 9, a)Tell me if there's a difference in the means for the two groups? Use a significance level of .05 for this question b)You'll assume, in...
2 - 3 5 7 8 10 11 12 13 Serial numbers for a product are to be made using 4 letters followed by 2 digits. The letters are to be taken from the first 5 letters of the alphabet, with no repeats. The digits are taken from the 10 digits (0, 1, 2, ..., 9), with no repeats. How many serial numbers can be generated? (If necessary, consult a list of formulas.) a 5 Continue Submit Assignment 2020 MGw.el...
Question 3. (20 pts) Let A= -3 9-27 2 -6 4 8 3 -9 -2 2 Find a basis for Col(A) and a basis for Nul(A). Question 4. (15 pts) Let the matrix A be the same as in Question 3. (1). Find the rank of A. (2). Find the dimensions of Nul(A) and Col(A). (3). How do the dimensions of Nul(A) and Col(A) relate to the number of columns of A?
Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...
Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...
Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...
Java The following questions ask about tracing a binary search. To trace the binary search, list the value of first, last, and mid for each pass through the loop or method. Use one of these methods for your trace. public static int binarySearchIterative(int[] numbers, int target) { boolean found = false; int first = 0; int last = numbers.length - 1; while (first <= last && !found) { int mid = (first + last) / 2; if (numbers[mid] == target)...
Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...