Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to Python Exam: Multiple Choice Questions and Answers, Exams of Computer Programming

A series of multiple-choice questions covering fundamental concepts in python programming. It includes questions on data types, functions, conditional statements, loops, strings, lists, dictionaries, and more. Each question is followed by the correct answer, providing a valuable resource for students preparing for python exams or seeking to reinforce their understanding of core programming concepts.

Typology: Exams

2024/2025

Available from 03/10/2025

essay-writers
essay-writers šŸ‡ŗšŸ‡ø

3.8

(91)

1.9K documents

1 / 64

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
INTRODUCTION TO PYTHON EXAM LATEST EXAM
2025 | ALL QUESTIONS AND CORRECT ANSWERS
(VERIFIED ANSWERS) | LATEST EXAM | ALREADY
GRADED A+ | JUST RELEASED
Which of the following is NOT an example of a function?
A. print
B. int
C. math.sin
D. math.pi ---------CORRECT ANSWER-----------------D. math.pi
Which of the following is an example of a Boolean expression?
A. a = a + b
B. a = 10
C. a += b
D. a % b == 2 ---------CORRECT ANSWER-----------------D. a % b == 2
The keyword True in Python is an example of which of the following?
A. A logical operator.
B. A Boolean.
C. A conditional.
D. An expression. ---------CORRECT ANSWER-----------------B. A Boolean.
What type of data results from the last line of the following code:
a += 10
b += 20
a == b
A. A logical operator.
B. A Boolean.
C. An expression.
D. A conditional. ---------CORRECT ANSWER-----------------B. A Boolean.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40

Partial preview of the text

Download Introduction to Python Exam: Multiple Choice Questions and Answers and more Exams Computer Programming in PDF only on Docsity!

INTRODUCTION TO PYTHON EXAM LATEST EXAM

2025 | ALL QUESTIONS AND CORRECT ANSWERS

(VERIFIED ANSWERS) | LATEST EXAM | ALREADY

GRADED A+ | JUST RELEASED

Which of the following is NOT an example of a function? A. print B. int C. math.sin D. math.pi ---------CORRECT ANSWER-----------------D. math.pi Which of the following is an example of a Boolean expression? A. a = a + b B. a = 10 C. a += b D. a % b == 2 ---------CORRECT ANSWER-----------------D. a % b == 2 The keyword True in Python is an example of which of the following? A. A logical operator. B. A Boolean. C. A conditional. D. An expression. ---------CORRECT ANSWER-----------------B. A Boolean. What type of data results from the last line of the following code: a += 10 b += 20 a == b A. A logical operator. B. A Boolean. C. An expression. D. A conditional. ---------CORRECT ANSWER-----------------B. A Boolean.

If a recursive function does not have a base case or cannot reach a base case, what will happen? A. The function will continue to call itself forever until the program crashes. B. The function will cause a syntax error in the program and the program will never run. C. The function will continue to call itself until a conditional statement is reached. D. The function will return a Boolean value after it completes 1000 iterations of the function. ---------CORRECT ANSWER-----------------A. The function will continue to call itself forever until the program crashes. In Python the following keywords are examples of what? and or not A. Logical operators. B. Boolean operators. C. Expressions. D. Conditional statements. ---------CORRECT ANSWER-----------------A. Logical operators. The Python keyword elif provides what to a program? A. Forced program termination B. Logical operators C. Branching D. Boolean values ---------CORRECT ANSWER-----------------C. Branching Consider the following: a is true b is false c is true

In the following string "This is a test" What is the character at index 5? A. i B. s C. a space D. a ---------CORRECT ANSWER-----------------A. i Which of the following is NOT true of strings in Python? A. The represent a sequence of characters. B. The have an index value associated with each character. C. The value of characters at specific indexes can be reassigned. D. They can contain zero characters. ---------CORRECT ANSWER------------ -----C. The value of characters at specific indexes can be reassigned. When comparing two strings using greater than or less than Boolean expressions, which of the following is true? A. Strings can only be compared when they are assigned to variables. B. Lowercase characters are evaluated as coming before uppercase characters. C. Strings are evaluated based on their length so longer strings are greater than smaller strings. D. Uppercase characters are evaluated as coming before lowercase characters. ---------CORRECT ANSWER-----------------D. Uppercase characters are evaluated as coming before lowercase characters. Which is a valid way to traverse the characters in a string? A. Using a conditional expression and the "len" function. B. Using a counter and a conditional expression. C. Using a "for" loop. D. Using the "find" method. ---------CORRECT ANSWER-----------------C. Using a "for" loop.

The len function can be used to determine the which of the following about a string? A. The value of the last index in the string. B. The number of non-space characters in the string. C. The number of characters in the string. D. The number of bits of memory that the string requires. ---------CORRECT ANSWER-----------------C. The number of characters in the string. To traverse a string you could use which of the following Python constructs? A. A loop. B. An assignment. C. A Boolean expression. D. A conditional. ---------CORRECT ANSWER-----------------A. A loop. The relationship between the value returned by the len function when run on a string and the last index of the string is which of the following? A. The last index is the value returned by len minus 1. B. It is dependent on the exact string and cannot be determined for the general case. C. The last index is the value returned by len plus 1. D. The last index is the value returned by len. ---------CORRECT ANSWER- ----------------A. The last index is the value returned by len minus 1. What is the length of an empty string? A. - 1 B. 0 C. It cannot be determined. D. 1 ---------CORRECT ANSWER-----------------B. 0 The plus sign '+' operator performs what task when used on two lists?

What is true about using a "for" loop with a "range" to access list items that is not true when a "for" loop is used to loop over the list items directly? A. You can find the length of the list. B. You can update the items in the list. C. You can guarantee that the loop will run at least once. D. You can print the items from the list. ---------CORRECT ANSWER--------- --------B. You can update the items in the list. The "split" method of a string produces which of the following? A. A list of words. B. The number of spaces used in the string. C. The a list of letters. D. The number of characters used to connect the string. ---------CORRECT ANSWER-----------------A. A list of words. Which is true of two objects that are equivalent? A. They must be identical. B. They cannot be identical. C. They are not necessarily identical. D. They are lists with the same values. ---------CORRECT ANSWER---------- -------C. They are not necessarily identical. The "pop" method returns which of the following? A. The updated list with the last value removed. B. The value that was removed from the list. C. The number of items left in the list. D. The index of the removed list. ---------CORRECT ANSWER----------------- B. The value that was removed from the list.

A reduce operation takes each element in a list and uses it to do which of the following? A. Combine multiple lists into a single list. B. Decrease the value at each position in the list. C. Produce a single value. D. Update the value at the specified position in the array. ---------CORRECT ANSWER-----------------C. Produce a single value. Which of the following is true of dictionaries in Python? A. They can be empty (have no keys or values). B. The value for a key cannot be a list. C. They can use lists as their keys. D. They may not be used within a list. ---------CORRECT ANSWER----------- ------A. They can be empty (have no keys or values). Which of the following is true of dictionaries in Python? A. Dictionaries cannot be returned from a function. B. Dictionaries cannot be passed to a function as an argument. C. Dictionaries can have multiple keys with different values. D. Dictionaries cannot have numeric keys. ---------CORRECT ANSWER----- ------------C. Dictionaries can have multiple keys with different values. What kind of data is considered "hashable"? A. all are hashable. B. integer numbers C. strings D. floating point numbers ---------CORRECT ANSWER-----------------A. all are hashable. Which of the following is NOT true of dictionaries in Python? A. You can retrieve a list of all the keys using the "keys" method.

D. Return a sorted list of the dictionary keys. ---------CORRECT ANSWER-- ---------------D. Return a sorted list of the dictionary keys. Which of the following is NOT a reserved keyword in Python? A. return B. finally C. start D. class ---------CORRECT ANSWER-----------------C. start What is true of arithmetic statements in Python? A. The Python interpreter always works from left to right with no regard for order of operations. B. Order of operations, including parentheses, is respected C. Parentheses cannot be used to enforce operational order D. Exponentiation is not guaranteed to occur before multiplication because they rely on similar characters. ---------CORRECT ANSWER-----------------B. Order of operations, including parentheses, is respected What is different about running a program as a script by sending a Python file to the Python interpreter versus running commands directly in the Python shell? A. In script mode, the output of each command will not be output to the screen. B. When running in the Python shell numbers do not need to be converted to strings contextually. C. Print statements are ignored when running in the Python shell. D. You cannot debug a program in script mode. ---------CORRECT ANSWER-----------------A. In script mode, the output of each command will not be output to the screen. Which of the following is true of strings in Python? A. They do not require quotes.

B. All normal arithmetic operators work on strings. C. They can be combined with numeric data without conversion. D. They can be surrounded by single or double quotes. ---------CORRECT ANSWER-----------------D. They can be surrounded by single or double quotes. The process of combining two strings is called... A. string addition B. concatenation C. joining D. assignment ---------CORRECT ANSWER-----------------B. concatenation Python is an example of what kind of programming language? A. Compiled B. Interpreted C. Natural D. Binary ---------CORRECT ANSWER-----------------B. Interpreted An expression is different from a statement because... A. an expression cannot be used in script mode but a statement can be. B. a statement cannot be used in script mode but an expression can be. C. an expression produces an effect on the program and a statement does not. D. a statement produces an effect on the program and an expression does not. ---------CORRECT ANSWER-----------------D. a statement produces an effect on the program and an expression does not. In the following expression, what best describes the relationship between number_of_students and the value 29: number_of_students = 29 A. number_of_students is a constant identified by 29 B. 29 is assigned to number_of_students

B. It makes the meaning of the code ambiguous. C. Python will fail with an error if you try to do this. D. It will overwrite the original value of the function and make it impossible to use that function again. ---------CORRECT ANSWER-----------------D. It will overwrite the original value of the function and make it impossible to use that function again. Which of the following operations is allowed to be used with string data? A. - B. * C. ** D. / ---------CORRECT ANSWER-----------------B. * When is It possible to perform addition on two different types of data using the "+" sign operator in Python? A. When one value is a number and one is a string representation of a number. B. When both are numeric types. C. This is never allowed without an explicit conversion of both values. D. Python always allows this because it is loosely typed. ---------CORRECT ANSWER-----------------B. When both are numeric types. When capturing user input in Python which of the following is true? A. Numeric input cannot be captured. B. Python will always always attempt to convert the data into a number first and will capture it as a string if that fails. C. The type of data captured from the user's input will be inferred based on the context. D. All user input will be captured as a string. ---------CORRECT ANSWER--- --------------D. All user input will be captured as a string.

When a floating point number is converted to an integer how is the original value changed? A. It is rounded up or down depending on the current value. B. It is truncated leaving just the whole number portion. C. The conversion will fail unless the decimal value is zero. D. It is rounded up to the nearest whole number. ---------CORRECT ANSWER-----------------B. It is truncated leaving just the whole number portion. Which of the following is NOT true of a statement in Python? A. A statement can be used to change the value stored in a variable. B. A simple line to print data is a statement. C. Statements produce an effect on the program. D. Statements only work with numeric data. ---------CORRECT ANSWER--- --------------D. Statements only work with numeric data. When attempting to convert a string value to an integer what will happen if a non-numeric string is used? A. A false value will be returned. B. The number will be returned as zero. C. The program will convert the ascii characters to numbers and return those. D. The program will crash with an error. ---------CORRECT ANSWER--------- --------D. The program will crash with an error. In Python once a variable is set to a specific value... A. it is set and cannot be reassigned. B. you must explicitly release the variable from memory in order to reset it. C. it can be set to any other data of any type. D. it cannot be set to a value of a different type. ---------CORRECT ANSWER-----------------C. it can be set to any other data of any type.

A. They can be accessed from outside the function as well as inside the function. B. They can be passed into the function as parameters. C. They can have the same name as a variable outside the function. D. They can store any type of information or data. ---------CORRECT ANSWER-----------------A. They can be accessed from outside the function as well as inside the function. In a Python program, to use a function... A. the function must return data. B. it must be defined above the calling code. C. it must not be a void function. D. the function can be declared anywhere in the program. --------- CORRECT ANSWER-----------------B. it must be defined above the calling code. Empty parentheses in a function header indicate... A. that the function is a void function. B. that the function doesn't take any arguments. C. that the function can take any number of arguments. D. that the function does not process data. ---------CORRECT ANSWER----- ------------B. that the function doesn't take any arguments. A function that does not return any data is called a ______ function. A. void B. fruitful C. empty D. variable ---------CORRECT ANSWER-----------------A. void What is the difference between a parameter and an argument? A. A parameter cannot be changed in the function, while an argument can be changed.

B. An argument is the data passed into the function when it is called. A parameter is the variable defined in the function header. C. A parameter is a local variable while an argument is global to the program. D. They are different words for the same thing. ---------CORRECT ANSWER-----------------B. An argument is the data passed into the function when it is called. A parameter is the variable defined in the function header. Which of the following is NOT true of a void function? A. They can accept input parameters. B. A variable assigned to the result of a void function will have a value of None. C. They do not return values. D. Since they cannot return data, they cannot perform any data manipulation. ---------CORRECT ANSWER-----------------D. Since they cannot return data, they cannot perform any data manipulation. When a function calls itself this is referred to as ... A. a nested function call. B. a recursive function call. C. an illegal function call. D. a Boolean function call. ---------CORRECT ANSWER-----------------B. a recursive function call Conditional statements allow which of the following? A. The ability to convert between data types. B. Alteration of the program behavior based on data in the program. C. The saving of Boolean values. D. Alternative syntax for manipulating variables. ---------CORRECT ANSWER-----------------B. Alteration of the program behavior based on data in the program.

When a return statement is followed by a mathematical expression which of the following is true? A. The function will run all code contained within it and then calculate the expression and return the value after all other code is completed. B. The expression will be converted to a Boolean value and returned. C. The expression will be calculated and the final result will be returned. D. The expression will be returned from the function and variables in the calling code will be used to produce the final calculation. ---------CORRECT ANSWER-----------------C. The expression will be calculated and the final result will be returned. When using a function that returns data in your program what is required to use the data in the calling code? A. The data can be stored in a variable but not passed to another function via composition. B. The data must be passed to another function via composition but cannot be stored in a variable. C. The result of the function must be captured in a variable or passed to another function via composition. D. The calling code cannot capture the return value directly. --------- CORRECT ANSWER-----------------C. The result of the function must be captured in a variable or passed to another function via composition. In a function such as the following: input_data = 20 def evaluate_data(input_data): if input_data == 10: return 'You guessed the number.' else: return 'You guessed wrong.' What will be returned from the function? A. The string 'You guessed wrong.' B. The string 'You guessed the number.' C. It cannot be determined from the given information.

D. A Boolean value. ---------CORRECT ANSWER-----------------C. It cannot be determined from the given information. In a function such as the following: def evaluate_data(input_data): if input_data == 10: return 'You guessed the number.' else: return 'You guessed wrong.' What will be returned from the function? A. It cannot be determined from the given information. B. The string 'You guessed wrong.' C. The string 'You guessed the number.' D. A Boolean value. ---------CORRECT ANSWER-----------------A. It cannot be determined from the given information. Which of the following is NOT true of a function that returns data? A. It can return a Boolean value. B. It may use conditonal logic to return data of different types. C. It can return a string value. D. It must accept input data in the form of parameters. ---------CORRECT ANSWER-----------------D. It must accept input data in the form of parameters. Which of the following is NOT true of Boolean functions? A. The Boolean value can be captured in a variable from the calling code. B. They must be named in such a way as to answer a yes/no question. C. They can have multiple return statements but only one return statement can be executed in a given run of the function. D. They can be used directly in a conditional statement. ---------CORRECT ANSWER-----------------B. They must be named in such a way as to answer a yes/no question.