e. This will throw an error since the argument of func is an integer x and len(x) will be the error showing that the object of type int has no len(). However, if in line 3, if we write range(x) instead of range(len(x)), then the answer will be 6. This function is finding sum from 0 to x-1.
f. Immutable objects are those objects whose values can not be changed after they are created. A tuple is an immutable list.
g. the first line declares a list nums having values 55,44,33,22.
nums[:2] will contain values up to index 2 i.e. 55,44.
min(nums[:2]) will find minimum value is nums[:2] which is 44.
abs(-42) will return absolute value of 42 i.e. 42.
now max(44,42) will be 44.
So, answer will be 44.
need help on all parts please and thank you (e) What is the correct output of...
convert the following code from python to java.
def topkFrequent(nums, k): if not nums: return [ ] if len(nums) == 1: return nums [0] # first find freq freq dict d = {} for num in nums: if num in d: d[num] -= 1 # reverse the sign on the freq for the heap's sake else: d[num] = -1 h = [] from heapq import heappush, heappop for key in di heappush(h, (d[key], key)) res = [] count = 0...
Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in PYTHON, new student. Please, please, I'm begging, Kindly answers all the questions. I'm hoping to grant my request. Thanks in advanced. 1.) What is the output of the following snippet? l1 = [1,2] for v in range(2): l1.insert(-1,l1[v]) print(l1) a.) [1, 2, 2, 2] b.) [1, 1, 1, 2] c.) [1, 2, 1, 2] d.) [1,...
How can I rewrite and better understand the code since it is not working. Thank you for helping me!! It means a lot :) CODE: import numpy as np def coeff(x): X = x[:,0] Y = x[:,1] if len(X)>=11: L = 10 else: L = len(X)-1 nm = np.zeros((L,1)) for i in range(1,L): fit = np.polyfit(X,Y,i) val = np.polyval(fit,X) nm[i-1,0] = np.linalg.norm(Y-val) I = nm.argmin() coeff = np.polyfit(X,Y,I) print(coeff)
Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX = 100 #gets an integer def getValidInt(MINN, MAXX): message = "Enter an integer between" + str(MINN) + "and" + str(MAXX)+ "(inclusive): "#message to ask the user num = int(input(message)) while num < MINN or num > MAXX: print("Invalid choice!") num = int(input(message)) #return result return num #counts dupes def twoInARow(numbers): ans = "No duplicates next to each...
PYTHON I need help with this Python problem,
please follow all the rules! Please help! THANK YOU!
Bonus Question Implement an efficient algorithm (Python code) for finding the 11th largest element in a list of size n. Assume that n will be greater than 11. det find 11th largest numberlissy Given, lissy, a list of n integers, the above function will return the 11th largest integer from lissy You can assume that length of lissy will be greater than 11....
Show the source code if possible or code writen with output please and thank you <3 6. Is the following a legal Python program? def proc(x, y): return 2*x + y*y def main(): print(proc(5)) main() 7. Is the following a legal Python program? def proc(x): return 2*x def main(): print(proc(5, 4)) main() 8. Is the following a legal Python program? def proc(x): print(2*x*x) def main(): proc(5) main()
Using Python3,
How can I aggregate the output from each iteration to one single
list? Because from the program I have right now, it gives me the
result of every iteration and gives me something like this as
individual results and not one large list:
None
None
...
None
130.0
None
...
1764
1765
None
To clarify, I have this program where it calculates the sum of
bytes sent within each incrementation of every 1 second, but there
are instances...
I need help for the order of growth for functions in Python 3. Q1: What is the order of growth for the following functions? Kinds of Growth Here are some common orders of growth, ranked from no growth to fastest growth: 1. Θ(1) — constant time takes the same amount of time regardless of input size 2. Θ(log n) — logarithmic time 3. Θ(n) — linear time 4. Θ(n log n) — linearithmic time 5. Θ(n2 ) 6. Θ(n3 ),...
Mele!!! Question 24 2 pts What is the output of the following code: def XXX(array,y): X = for i in range (y): x += array[i] print (x) list=[10,20,30] XXX(list, 3) 60 N 3 0
Python, I need help with glob. I have a lot of data text files and want to order them. However glob makes it in the wrong order. Have: data00120.txt data00022.txt data00045.txt etc Want: data00000.txt data00001.txt data00002.txt etc Code piece: def last_9chars(x): return(x[-9:]) files = sorted(glob.glob('data*.txt'),key = last_9chars) whole code: import numpy as np import matplotlib.pyplot as plt import glob import sys import re from prettytable import PrettyTable def last_9chars(x): return(x[-9:]) files = sorted(glob.glob('data*.txt'),key = last_9chars) x = PrettyTable() x.field_names =...