Docsity

Introduction to Python Exam 2025-2026 | Programming Practice Test & Study Guide, Exams of Introduction to Computing

Partial preview of the text

Download Introduction to Python Exam 2025-2026 | Programming Practice Test & Study Guide and more Exams Introduction to Computing in PDF only on Docsity!

Page 1 of 159 INTRODUCTION TO PROGRAMING IN PYTHON EXAM / PYTHON MIDTERM EXAM 2026/2027 AND STUDY GUIDE COMPLETE ACCURATE EXAM ACTUAL QUESTIONS AND CORRECT DETAILED ANSWERS (EXPERT VERIFIED SOLUTIONS) NEWEST UPDATED VERSION 2026 | GUARANTEED PASS. (BRAND NEW!) | FULL REV Q1. What is the output of print(2 ** 3 ** 2)2 A) 64 Page 2 of 159 B) 512 C) 256 D) 12 Correct Answer: B) 512 Rationale: Exponentiation is right-associative: 2 ** (3 ** 2) = 2**9 = 512. Q2. Which is a valid variable name? A) 2var B) var-2 C) _var2 D) var 2 Correct Answer: C) _var2 Rationale: Variables can start with underscore or letter, not digit; no spaces/hyphens. Page 4 of 159 Q5. Scenario: price = 10, tax = 0.05, total = price + price * tax. What is total? A) 10.05 B) 10.5 Cc) 10 D) 10.50 Correct Answer: B) 10.5 Rationale: price * tax = 0.5, plus 10 = 10.5. Q6. Which reads user input as a string? A) input("Enter: ") B) raw_input("Enter: ") C) read("Enter: ") D) get_input("Enter: ") Correct Answer: A) input("Enter: ") Rationale: Python 3 input() always returns string. Page 5 of 159 Q7. What does len("Hello\nWorld") return? A) 10 B) 11 ¢) 12 D) 9 Correct Answer: B) 11 Rationale: \n is one char — 11 chars total. Q8. Which is NOT a Python keyword? A) None B) True C) false D) and Correct Answer: C) false Rationale: Python uses False, not false. Page 7 of 159 Q11. What is 'Python'[1:4]? A) 'yth' B) 'yt' C) 'ytho' D) 'Pyt' Correct Answer: A) 'yth' Rationale: Indices O:P,1:y,2:t,3:h,4:0,5:n — [1:4] = y,t,h. Q12. Which operator tests identity? A) == B) = C) is D) != Correct Answer: C) is Q13. What is bool([])? A) True Page 8 of 159 B) False C) None D) Error Correct Answer: B) False Rationale: Empty sequences are falsy. Q14. Scenario: x = 10; y = x; y = 20. What is x? A) 10 B) 20 C) None D) Error Correct Answer: A) 10 Rationale: Integers are immutable; y points to new object. Q15. Convert string "123" to integer: A) int("123") B) str(123) Page 10 of 159 Correct Answer: B) 5.0 Q18. Scenario: You need to swap a and b. Which works? A)a=b;b=a B) a,b =b,a C) temp = a; b = a; b = temp D) swap(a, b) Correct Answer: B) a, b = b, a Q19. What is type(True)? A) B) C) D) Correct Answer: A) Page 11 of 159 Q20. Output of print(3 * 'hi')? A) hihihi B) hihihi (same) C) hihihihihi D) Error Correct Answer: A) hihihi Q21. ‘abc’ + 'def' yields? A) 'abcdef" B) 'abc def’ C) Error D) ‘abc+def' Correct Answer: A) 'abcdef' Q22. Scenario: User enters 25. How to store as int? python Page 13 of 159 B) False C) Error D) None Correct Answer: B) False Rationale: Floating-point precision issue. Q25. Best way to check type of variable x? A) type(x) B) typeof(x) C) x.type() D) class(x) Correct Answer: A) type(x) Q26. What is round(2.675, 2)? A) 2.67 B) 2.68 C) 2.7 Page 14 of 159 D) 2.68 (but bank rounding; actual Python: 2.67 due to binary representation) Correct Answer: A) 2.67 (expert note: float representation causes this) Q27. print("hello".upper()) outputs? A) hello B) HELLO C) Hello D) hELLO Correct Answer: B) HELLO Q28. len("") returns? A)O B) 1 C) None D) Error Page 16 of 159 Q31. print(10 == 10.0)? A) True B) False C) Error D) None Correct Answer: A) True Q32. Which is a valid escape sequence? A) \n B) \t Cc) \\ D) All of above Correct Answer: D) All of above Page 17 of 159 Q33. print(‘It\'s nice’) output? A) It's nice B) It's nice C) Error D) It’s nice Correct Answer: A) It's nice Q34. int(3.99) returns? A)3 B) 4 C) 3.99 D) Error Correct Answer: A) 3 (truncates toward zero) Q35. Scenario: You want x to be None. Which is correct? A) x = None B) x = "None" Page 19 of 159 Answer: B) 512 Q38. bool(-1)? A) True B) False C) None D) Error Answer: A) True Q39. Which is not a numeric type? A) int B) float C) complex D) decimal Answer: D) decimal (not built-in numeric type, but in module) Page 20 of 159 Q40. Scenario: You have s = "Python". Get last character. A) s[0] B) s[-1] C) s{6] D) s[len(s)] Answer: B) s[-1] Q41. print(3 < 5 and 5 < 3)2 A) True B) False C) Error D) None Answer: B) False Q42. print(not True or False)? A) True B) False