Question
need help on all parts please and thank you
(e) What is the correct output of this code? (2 pts) >>> def func(x): >>> res = 0 >>> for i in range (len (x)): res i >>> ret
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
need help on all parts please and thank you (e) What is the correct output of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • convert the following code from python to java. def topkFrequent(nums, k): if not nums: return [...

    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...

    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...

    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 =...

    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...

    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...

    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...

    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...

  • Mele!!! Question 24 2 pts What is the output of the following code: def XXX(array,y): X...

    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...

    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 =...

  • PYTHON please help, stuck on this output and memory image! THANK YOU! Q3 7 Points import...

    PYTHON please help, stuck on this output and memory image! THANK YOU! Q3 7 Points import copy list1 = [11, [22, 33], [44, 55], 66] list2 = list1 list3 = listi[:] list4 = copy.deepcopy(listi) list1[0] = 100 list1[1][1] = 300 list1 += [77] list2 = list2 + [88] print(listi) print(list2) print(list) print(list) Please write output of the above program below (in the text box) and upload a picture of memory image? Enter your answer here Memory Image: Please select file(s)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT