Quiz 2 Answers

pdf

School

San Jose State University *

*We aren’t endorsed by this school

Course

258

Subject

Electrical Engineering

Date

Jan 9, 2024

Type

pdf

Pages

7

Uploaded by MagistratePorpoiseMaster286

Report
Quiz #2 (Python) Due Oct 27 at 11:59pm Points 10 Questions 10 Available after Oct 26 at 12am Time Limit 10 Minutes Score for this quiz: 4 out of 10 Submitted Oct 27 at 11:50pm This attempt took 10 minutes. A ! empt History Attempt Time Score LATEST Attempt 1 10 minutes 4 out of 10 1 / 1 pts Question 1 What is the result of the following python code? >>> vec = ['Mary', 'had', 'lamb'] >>> for i in range(len(vec)-2): print(i+1, a[i+1]) 0 Mary 2 lamb 0 had 1 had Correct! Correct! 1 / 1 pts Question 2
What is the result of the following python code? >>> for n in range(5, 6, 1): for x in range(2, n): if n % x == 0: print(n, 'equals', x, '*', n//x) break else: # loop fell through without finding a factor print(n, 'is a prime number') 3 is a prime number 4 equals 2 * 2 5 is a prime number Correct! Correct! 6 equals 2 * 3 0 / 1 pts Question 3 What is the result of the following python code? def f(a,L=[]): L.append(a) return L f(5) print(f(1)) [1] You Answered You Answered You Answered You Answered [5, 1] Correct Answer Correct Answer Correct Answer Correct Answer [5]
[] 1 / 1 pts Question 4 What is the result of the following python code? [(x, y) for x in [1,2] for y in [1, 4] if x == y] [(2, 4)] [(1, 1)] Correct! Correct! [(4, 2)] [(1, 1), (2,4)] 0 / 1 pts Question 5 What is the result of the following python code? >>> matrix = [ [1, 2, 3], [5, 6, 7], ] list(zip(*matrix)) [(1, 5), (2, 6), (3, 7)] Correct Answer Correct Answer Correct Answer Correct Answer
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
[1, 2, 3, 5, 6, 7] [1, 2, 3] [(1, 2, 3), (5, 6, 7)] You Answered You Answered You Answered You Answered 0 / 1 pts Question 6 What is the result of the following python code? >>> MM = {'Alg': 'MLP'} >>> for k in MM.keys(): print(k) k You Answered You Answered You Answered You Answered MLP Alg MLP Alg Correct Answer Correct Answer Correct Answer Correct Answer 0 / 1 pts Question 7 What is the result of the following python code? >>> class Complex: def __init__(self, realpart = 0, imagpart = 0): self.r = realpart
self.i = imagpart x = Complex() x.r, x.i (0, 3) 0 You Answered You Answered You Answered You Answered (0, 0) Correct Answer Correct Answer Correct Answer Correct Answer (3, 4) 0 / 1 pts Question 8 What is the result of the following python code? class Dog: kind = 'canine' # class variable shared by all instances def __init__(self, name): self.name = name d = Dog('Fido') e = Dog('Sersem') e.kind 'Sersem' You Answered You Answered You Answered You Answered 'Fido' 'Name' 'canine Correct Answer Correct Answer Correct Answer Correct Answer
0 / 1 pts Question 9 What is the result of the following python code? def f1(self, x = 1, y = 2): return min(x, x+y) class CC: f = f1 def g(self): return 'hello world' myClass = CC() myClass.f() 1 Correct Answer Correct Answer Correct Answer Correct Answer self 2 'hello world' You Answered You Answered You Answered You Answered 1 / 1 pts Question 10 Which of the following commands display the first 5 rows of a pandas dataframe dataset? dataset.head() Correct! Correct! dataset.hist()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
dataset.info() dataset.describe() Quiz Score: 4 out of 10