Docsity

Fundamentals of Python, First Programs, 3rd Edition Lambert, Exams of Technology

Partial preview of the text

Download Fundamentals of Python, First Programs, 3rd Edition Lambert and more Exams Technology in PDF only on Docsity!

Accredited Test Bank Solution For

Fundamentals of Python, First Programs,

3rd Edition Lambert [All Lessons

Included]

 Rapid Download

 Quick Turnaround

 Complete Chapters Provided

Complete Chapter Solution Manual

are Included (Ch.1 to Ch.13)

Table of Contents are Given Below

Here is the table of contents for Fundamentals of Python: First Programs, 3rd Edition by Kenneth A. Lambert:

  1. Introduction
  2. Data Types and Expressions
  3. Control Statements
  4. Strings and Text Files
  5. Lists and Dictionaries
  6. Design with Functions
  7. Design with Recursion
  8. Simple Graphics and Image Processing
  9. Graphical User Interfaces
  10. Design with Classes
  11. Data Analysis and Visualization
  12. Network Applications and Client/Server Programming
  13. Searching, Sorting, and Complexity sThis edition introduces programming and problem-solving using Python, gradually transitioning from simple code snippets to realistic applications, including graphics, image processing, GUIs, and data visualization. CHAPTER 1: INTRODUCTION Question 1 What is the correct file extension for Python files? a) .pyth b) .pt c) .py d) .pyt Answer: c) .py Explanation: Python source files use the .py extension.

Question 5 What is the output of the following code? python Copy print("Hello, World!") a) Hello, World! b) Hello, World c) "Hello, World!" d) Hello World! Answer: a) Hello, World! Explanation: The print() function outputs the string exactly as provided, including punctuation. Question 6 Which keyword is used to define a function in Python? a) func b) define c) def d) function Answer: c) def Explanation: The def keyword is used to define functions in Python. Question 7 How do you create a single-line string in Python? a) 'Hello' b) "Hello" c) Both a and b d) """Hello""" Answer: c) Both a and b Explanation: Python allows single-line strings to be enclosed in either single (' ') or double (" ") quotes.

Question 8 Which of the following is NOT a valid data type in Python? a) int b) float c) char d) str Answer: c) char Explanation: Python does not have a char data type; single characters are represented as strings of length one. Question 9 Which of the following is used to take input from the user in Python? a) input() b) read() c) scanf() d) get() Answer: a) input() Explanation: The input() function is used to receive input from the user as a string. Question 10 What is the correct syntax to start a conditional statement in Python? a) if x == 5 then: b) if (x == 5) { c) if x == 5: d) if x = 5: Answer: c) if x == 5: Explanation: Python uses if followed by the condition and a colon : to start a conditional block. The equality operator is ==.

a) tuple b) str c) list d) int Answer: c) list Explanation: Lists are mutable, meaning their elements can be changed after creation. Tuples and strings are immutable. Question 15 What is the output of len("Python")? a) 5 b) 6 c) 7 d) Error Answer: b) 6 Explanation: The len() function returns the number of characters in the string "Python", which is 6. Question 16 How do you create a dictionary in Python? a) [] b) {} c) () d) <> Answer: b) {} Explanation: Dictionaries in Python are created using curly braces {}, with key-value pairs inside. Question 17 Which of the following correctly assigns the value True to variable flag? a) flag = 'True' b) flag = True

c) flag = "True" d) flag = 1 Answer: b) flag = True Explanation: In Python, True is a boolean value and should not be enclosed in quotes. Question 18 What is the result of 'Hello' + 'World' in Python? a) 'HelloWorld' b) 'Hello World' c) Error d) 'Hello+World' Answer: a) 'HelloWorld' Explanation: The + operator concatenates the two strings without adding a space. Question 19 Which function converts a string to an integer in Python? a) str() b) int() c) float() d) bool() Answer: b) int() Explanation: The int() function converts a string or number to an integer. Question 20 What does the expression 5 > 3 and 2 < 4 evaluate to? a) True b) False c) Error d) None Answer: a) True

Question 24 What is the type of the following expression: 3 + 4.5? a) int b) float c) str d) complex Answer: b) float Explanation: Adding an integer and a float results in a float. Question 25 Which of the following is used to create a multi-line string in Python? a) ' b) " c) ''' or """ d) // Answer: c) ''' or """ Explanation: Triple quotes ''' or """ are used for multi-line strings in Python. Question 26 What does the is operator do in Python? a) Checks value equality b) Checks type equality c) Checks identity d) Assigns a value Answer: c) Checks identity Explanation: The is operator checks whether two variables point to the same object in memory. Question 27 Which of the following is the correct way to define a tuple in Python?

a) [1, 2, 3] b) (1, 2, 3) c) {1, 2, 3} d) <1, 2, 3> Answer: b) (1, 2, 3) Explanation: Tuples are defined using parentheses (). Question 28 What is the output of bool(0) in Python? a) True b) False c) 0 d) None Answer: b) False Explanation: In Python, 0 is considered False when converted to a boolean. Question 29 Which method is used to remove whitespace from both ends of a string in Python? a) strip() b) trim() c) remove() d) delete() Answer: a) strip() Explanation: The strip() method removes leading and trailing whitespace from a string. Question 30 What is the result of 10 % 3 in Python? a) 1 b) 3 c) 0 d) Error

Question 34 Which of the following is used to perform integer division in Python? a) / b) // c) % d) ** Answer: b) // Explanation: The // operator performs floor (integer) division. Question 35 How do you access the first element of a list my_list in Python? a) my_list[0] b) my_list[1] c) my_list.first() d) my_list.get(1) Answer: a) my_list[0] Explanation: Lists are zero-indexed in Python, so the first element is at index 0. Question 36 Which keyword is used to check if a condition is not true in Python? a) not b) none c) false d) null Answer: a) not Explanation: The not keyword negates a boolean condition.

Question 37 What is the result of 'a' in 'apple' in Python? a) True b) False c) 'a' d) 'apple' Answer: a) True Explanation: The character 'a' is present in the string 'apple', so the expression evaluates to True. Question 38 Which function is used to get the integer value from a float in Python? a) int() b) float() c) str() d) bool() Answer: a) int() Explanation: The int() function converts a float to an integer by truncating the decimal part. Question 39 What is the result of True + True in Python? a) 2 b) True c) Error d) 1 Answer: a) 2 Explanation: In Python, True is equivalent to 1 , so True + True equals 2. Question 40 Which of the following will raise a TypeError in Python?

Answer: a) + Explanation: The + operator concatenates two lists. Question 44 What is the result of bool("False") in Python? a) True b) False c) Error d) None Answer: a) True Explanation: Non-empty strings are considered True in Python, regardless of their content. Question 45 Which method adds an element to the end of a list in Python? a) append() b) add() c) insert() d) extend() Answer: a) append() Explanation: The append() method adds a single element to the end of a list. Question 46 What does the range(5) function generate in Python? a) 0, 1, 2, 3, 4 b) 1, 2, 3, 4, 5 c) 5 d) Error Answer: a) 0, 1, 2, 3, 4 Explanation: range(5) generates numbers from 0 up to but not including 5.

Question 47 How do you retrieve the value associated with key 'age' in dictionary person? a) person.age b) person['age'] c) person.get('age') d) Both b and c Answer: d) Both b and c Explanation: You can access dictionary values using person['age'] or the get() method: person.get('age'). Question 48 Which of the following is a valid way to define a boolean variable in Python? a) is_valid = "True" b) is_valid = True c) is_valid = 1 d) Both b and c Answer: d) Both b and c Explanation: In Python, True is a boolean value, and 1 is interpreted as True in a boolean context. However, for clarity, it's best to use True. Question 49 What is the output of print(2 ** 3 ** 2) in Python? a) 64 b) 512 c) 256 d) Error Answer: b) 512 Explanation: The expression is evaluated as 2 ** (3 ** 2) = 2 ** 9 = 512 due to right associativity of the ** operator.

a) ''' Comment ''' b) // Comment c) /* Comment */ d) # Comment Answer: a) ''' Comment ''' Explanation: Triple quotes can be used to create multi-line strings, which can serve as multi-line comments if not assigned to a variable. Question 54 What is the output of print(3 > 2 > 1) in Python? a) True b) False c) Error d) None Answer: a) True Explanation: Chained comparisons are allowed in Python and evaluate to True if all comparisons are True. Question 55 Which of the following methods can be used to find the index of an element in a list? a) find() b) index() c) locate() d) search() Answer: b) index() Explanation: The index() method returns the first index of the specified value. Question 56 What does the len() function return when called on a dictionary? a) Number of keys b) Number of values

c) Number of key-value pairs d) Both a and c Answer: d) Both a and c Explanation: In dictionaries, len() returns the number of key-value pairs, which is equal to the number of keys. Question 57 How do you convert a list to a tuple in Python? a) tuple(list) b) list.to_tuple() c) convert(list, tuple) d) tupleize(list) Answer: a) tuple(list) Explanation: The tuple() constructor converts a list into a tuple. Question 58 Which of the following is a correct way to slice the list numbers = [0,1,2,3,4,5] to get [2,3,4]? a) numbers[2:5] b) numbers[2,3,4] c) numbers(2:5) d) numbers[2:4] Answer: a) numbers[2:5] Explanation: Slicing numbers[2:5] retrieves elements at indices 2, 3, and 4. Question 59 Which of the following is the correct way to define a function that returns the square of a number? a) python Copy def square(x): return x * x