Practice1_Spring_2024

docx

School

Columbia University *

*We aren’t endorsed by this school

Course

5210

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

5

Uploaded by DeaconHare3679

Report
Python for Data Analysis – Practice #1 1. What is the output of the code below? print(list(range(5))) a. 1, 2, 3, 4, 5 b. (0, 1, 2, 3, 4, 5) c. [0, 1, 2, 3, 4] d. (0, 1, 2, 3, 4) e. None of the above Answer: e 2. What is the output of the code below? x = 15 // 2 y = 14 % 3 z = 11 / 2 print (‘Values are’, x, y, z) a. Values are 7.5 2 5.5 b. Values are 7 2 5.5 c. Values are (7.5, 2, 5.5) d. None of the above Answer: b 3. What will the code below print? def f(x): return x*x for n in [2, 3, 5]: print (f(n), end = ‘’) a. 4 9 25 b. 2, 3, 5 c. [2, 3, 5] d. [4, 9, 25] e. none of the above Answer: a
4. Which is the output of the code below if for the first input user will type in 5 and for the second user will input 6? x = int(input('Enter a number: ')) y = input('Enter another number: ') print('The product is ', x*y) a. The product is 30 b. The product is 5*6 c. The product is 30.0 d. None of the above Answer: d 5. Given the statement below, what is My_List[2]: My_ List = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] a. [3] b. [4, 5, 6] c. [7, 8, 9] d. none of the above Answer: C 6. What is the output of the code below? str = ‘Hello World’ print(str[2:5]) a. ello b. llo c. Hello d. None of the above Answer: b 7. Which of these is not a Python data type? a. int b. long c. decimal d. float Answer: c
8. What is the output of the code below? x = 1 def calc_1(): x = 2 y = 3 return x calc_1() print (calc_1()) print (x) a. 1 1 b. 2 2 c. 2 1 d. none of the above Answer: c 9. Which is the output of the code below? total = 0 def sum1(n): total = 0 for i in range(n): total = total + i return total def sum2(k): total = 0 for j in range(k): total = total + j return total print(total) print(sum1(5)) print(total) print(sum2(7)) print(total) a. 0 b. 0 c. 0 d. None of the above 10 10 10 0 10 0 21 21 21 0 10 21 Answer: a
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
10.What is the output of the code below? def f(): global str print(str) str = "I love New York!" print(str) str = "I prefer London in Spring!" f() print(str ) a. I prefer London in Spring! I love New York! b. I love New York! I love New York! I prefer London in Spring! c. I prefer London in Spring! I love New York! I love New York! d. None of the above Answer: c 11. What is the result of the following Boolean expression, given that a = 6 , b = 7 , and c = 1 ? a < b or c > a a. True b. False c. 8 d. 5 Answer: a 12. Which of the following is the correct if clause to determine whether market is not equal to 10 ? a. if market != 10 b. if market != 10: c. if market <> 10: d. if not(market < 10 and choice > 10): Answer: b