Docsity

Python Programming Quiz: Basic Data Types, Functions & Debugging Questions with Solutions., Exams of Database Programming

Partial preview of the text

Download Python Programming Quiz: Basic Data Types, Functions & Debugging Questions with Solutions. and more Exams Database Programming in PDF only on Docsity!

SECTION 3 Basic Data Types 1. Which of the following is not a Python data type? Integer Number String Boolean ao7p 2. What constructor function would you use to convert a string to a boolean? true() boolean() int() bool() pase 3. Which option below is a valid string? a. ‘Hello’ b. “There is nothing ‘scaley’ about the Python language” c. ‘His name is Chase but he goes by “Chase” d. “Enter your name” e. All of the above 4. All data types discussed in the chapter have a truth value. a. True b. False 5. Whatis the result of the function int (2.2)? a. An error b. 4 c. 3 d. 3.2 SECTION 4 Built-In Functions 41. Which of the following is not a Python built-in function? Page 1 of 9 c. Lastname d. Last_name 8. Functions need to have a return statement. a. True b. False 9. Which of the following is not a comparison operator? a= b. & d. eo =< 10. What is the correct answer to the expression 5 // 2? a 10 bo 1 c 2 d. 3 SECTION 6 Errors and Debugging 1. What Python built-in function is useful for debugging? debug() input() print() error() log() paore 2. What two keywords are used to handle errors in Python? a. Try, error b. Try, accept c. Try, iffailure d. Try, except e. None of the pairs are correct. 3. APython Traceback lists the most recent function call first. a. True b. False 4. Which of the following errors does not exist as a Python built in exception? a. IndentationError b. TypeError c. NamecError d. SyntaxError e. Allare Python built in exceptions 5. Expert programmers dan’t program accidental bugs into their code. a. True b. False SECTION 7 Python Keywords 1. Which of the following is not a Python keyword? Page 5 of 9 2. You can change what Python keywords do. a. True b. False 3. The variable name = ‘Jonn’ has been declared. Which of the below statements is valid Python? a. name is not True b. name is True or False ¢. name > ‘hello’ and name is not None d. name is > ‘hello’ and name is None 4. The keyword ¢lobal is used to: a. Access a global variable in the local scope of a function b. Change the values for all the variables’ name with that variable name c. Declare a variable d. None of the answers define what the global keyword does. SECTION 8 Basic Logic 1. Which of the following keywords are not valid in if-else statements. a if b. ifel c. elif d. else e. or 2. You can nest if-else blocks inside of other if-else blocks. a. True b. False 3. Which statement below is incorrect. a. Else blocks can be empty b. You can only use one c1if keyword per if-else block. c. If-else blocks aren't typically used for decision making in Python programs. d. None of the above statements are correct. SECTION 9 Advanced Data Types 1. Given the variable 1s = [‘cat’, ‘dog’, ‘goldfish’, ‘snake’ ), which Python statement makes the slice a. b. c. d. 1s[1:3] 2. Which of the following key-value pairs is not valid? a ‘first’: ‘John’} b. 22.3: 4} ©. {[\Charles’]: ‘blue’ } Page 7 of 9 d. £4: None} 3. You can change the values in lists but not in dictionaries. RS \ Page 8 of 9