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