Partial preview of the text
Download intro to python quizzes with comp and more Exams Biology in PDF only on Docsity!
intro to python quizzes with complete verified solutions 2025 Which of the following is NOT a reserved keyword in Python? A. return B. finally C. start D. class 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. 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. 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. D. They can be surrounded by single or double quotes. A. number_of_students is a constant identified by 29 B. 29 is assigned to number_of_students C. 29 is a constant identified by number_of_students D. 29 is equivalent to number of students What is true of variable names in Python? A. They cannot begin with an uppercase letter. . D. Th itive. B. They can include spaces ey are case sensitive C. Numbers can be used anywhere in the variable name. D. They are case sensitive. In a Python program the type of which of the following values are the same? 10 10.0 10' A. None are the same. A. None are the same. B. The first two are the same. C. All are the same. D. The second two are the same When a piece of data is converted from one type to another type it is called... D. type casting A. conversion B. concatenation C. polymorphism D. type casting Why is it a bad idea to use words such as print and other Python built in functions as variable names? A. Python will reset your variables while the program is running. D. It will overwrite the original value of the function and make it impossible to use that function again. 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. Which of the following operations is allowed to be used with string data? A.- B.* C. kk D./ When is It possible to perform addition on two different types of B. When both are numeric types. data using the "+" sign operator in Python? A. When one value is a number and one is a string representation of a number. 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. 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. 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. C. it can be set to any other data of : any type. Which of the following is true of variables in Python? A. Once a variable is set with a value it cannot be changed. B. The type of value stored in a variable does not need to be defined or declared. B. The type of value stored ina variable does not need to be defined or declared. C. Variables are not available in script mode. D. The type of value stored in a variable must always be declared. When reading a traceback, which piece of data is NOT available? A. the data currently stored in the variables. B. the list of function names that were A. the data currently stored in the called. : variables. C. the function name in which the error occurred. D. the line number on which the error occurred. : 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. Empty parentheses in a function header indicate... A. that the function is a void function. B, that the function doesn't tak ; ab ine Tunction doesn trane any : B. that the function doesn't take any arguments. arguments. C. that the function can take any number of arguments. D. that the function does not process data. : A function that does not return any data is calleda____ function. H A. void B. fruitful C. empty D. variable | A. void What is the difference between a parameter and an argument? B. An argument is the data passed | into the function when it is called. A : parameter is the variable defined in A. A parameter cannot be changed in - ' the function header. 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. 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 } . . : g : D. Since they cannot return data, they a void function will have a value of ' ‘ cannot perform any data None. P y manipulation. C. They do not return values. D. Since they cannot return data, they cannot perform any data manipulation. Which of the following is NOT an example of a function? H A. print B. int D. math.pi C. math.sin D. math.pi Which of the following is an example of a Boolean expression? A.a=atb B.a = 10 C.at=b D.a%b==2 :D.a%b==2 iterations of the function. In Python the following keywords are examples of what? and or not A. Logical operators. B. Boolean operators. C. Expressions. D. Conditional statements. A. Logical operators. The Python keyword elif provides what to a program? A. Forced program termination B. Logical operators C. Branching D. Boolean values C. Branching Consider the following: ais true bis false cis true then which of the following statements is correct? A.aand b and cis true B. not b or cis false C. b and nota is true D.aand b and cis false D. a and b and cis false When an if/else block is fully contained within an if/elif/else statement, this is referred to as ... A.a chained conditional statement. C.anested conditional statement. B. a compound logical operation. C. a nested conditional statement. D. an enhanced Boolean operation. When a function calls itself this is referred to as ... A.a nested function call. . . B. a recursive function call B. a recursive function call. C. an illegal function call. D. a Boolean 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. i B. Alteration of the program behavior ; based on data in the program. C. The saving of Boolean values. D. Alternative syntax for manipulating variables. Which of the following is NOT a mathematical function that returns a value? A. math.pi A. math.pi B. math.log C. math.isfinite C. The function will end and always return a Boolean value. D. The function will continue running until all the code is executed but will return the value associated with the return statement. 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. C. The expression will be calculated B. The expression will be converted to . . P and the final result will be returned. 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. When using a function that returns C. The result of the function must be data in your program what is : captured in a variable or passed to required to use the data in the calling ! another function via composition. code? A. The data can be stored ina 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. 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. i 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. A. It cannot be determined from the given information. total = total - 20 total + 100*5 total += 3 A. 685 B. 183 C. 184 D. 683 E. it cannot be determined from the given data Based on the following code, what is the final value of comparison? a+=10 b += 20 a = input(‘Enter a number’) b=50 test = b <= 50 check = a==b comparison = test and check A. it cannot be determined from the given data. B. this code contains illegal data or syntax errors. C. false D. true C. false The range in Python creates which of the following? A. A sequence of numbers. A. A sequence of numbers. B. A Boolean value. C. Two numbers. D. A number. The range function accepts a third argument which changes which of the following? A. The starting value of the sequence. : B. The difference between numbers in B. The difference between numbers in } the sequence. the sequence. C. The final value of the sequence. D. The number of values to generate. Which of the following must happen for a "while" loop to terminate (assuming there is no break statement in the loop)? A. The loop must produce a mathematical result. B. The loop condition needs to be B. The loop condition needs to be altered within the loop body. altered within the loop body. C. The loop must produce the proper final data. D. The loop must complete at least two iterations. If a while loop does not have a proper terminating condition which of the following will occur? ! C. The loop will run forever. A.A break statement will be implicitly : understood to be part of the loop and will terminate it.