Font size
WorksheetsProgramming Quiz
Total questions: 95
Worksheet time: 3hrs 38mins
What is the output of this code snippet where x=4 and then x is set to "Sally"?
Which is an example of Python string addition that will run without error?
Hello" + "World!"
new_string = Hello + World! All choices message1 'Hello' + 'World!'
message1 = 'Hello' + 'World!'
In programming paradigms, increased levels of abstraction usually mean that the language approaches human readability and becomes less tied to the intricacies of specific hardware. Would you agree?
True
False
The string.isdigit() does what?
Returns True if all characters in the string are lowercase
Returns True if the string is a title-cased string otherwise returns False
Returns True if all characters are alphabetical or digits
In Python, you can use the in operator to check if a value exists in a group of values.
True
False
What will be the output of the following Python code snippet where game One Points = 200, game TwoPoints=456, and an attempt is made to print game One Points + game TwoPoints?
Using the following list of players, what will be the output when print(players[1:5]) is used?
What value is stored in the "total" variable after the following code runs: for i in range(1,5): total = total + i?
In Python, what is the maximum number of parameters a function can accept?
Choose the statement that will print the letter "O", given the variable declaration word "MACBOOK"
print(word[-1])
print(word[3])
print(word[2])
print(word[-2])
Which of the following are characteristics of tuples in Python? (Select all that apply) Tuples can contain elements of different data types
Tuples are ordered
Tuples support item assignment
Tuples are mutable
Tuples can contain elements of different data types
print("It's time to code") What is the output of the above code?
The while loop takes a collection of items and executes a block of code once for each item in the collection. False
What will be the output of the following program, if the user entered 20 and then 41? Number1 = input("Enter the first number: ") Number2= input("Enter the second number: ") print(Number1 + Number2
How can you create a tuple with a single element?
(element)
(element.)
element
(element)
(element,)
Which of the following is not a valid operation on tuples?
Modifying an element at a specific index
Finding the length using the len() function
Concatenation using the + operator
Accessing elements by index
What does the Python code: score = 3 + "45" result in?
What is the output of this code? x = 5 y = "John" print(x) print(y)
Which of the following operations are supported by tuples in Python? (Select all that apply)
Slicing using the [] operator
Appending elements using the append() method
Repetition using the * operator
Concatenation using the + operator
Using the list fruits ("apple", "banana", "cherry"), how would you add "orange" to the end?
fruits.append("orange")
fruits add("orange")
fruits push("orange")
fruits.put("orange")
Using the following code, answer the following question. players = ['Tage Thompson', 'Alex Tuch', 'Dylan Cozens', 'Owen Power', 'Rasmus dahlin', 'Jeff Skinner'] print("Here are some players on the Buffalo Sabres:") for player in players[4]: print(player.title()) What is the correct output?
What is the output from running the following code? x=0 while x < 5: x += 1 print("loop")
Using singular and plural names can help you identify whether a section of code is working with a single element from the list or the entire list. What is the output from running the above code most like?
No output
time is 3
time is 4
Among the following options, which language operates closer to machine code and does not provide the abstracted features typically associated with high-level programming languages?
Assembly Language
Python
Java
C++
In a list called "players" if you wanted to delete the third element in the list which of the following examples of code would be correct?
players.pop(2)
players.remove(2)
players.delete(2)
players.cut(2)
What is the output when print(players[1:4]) is used?
['Josh Allen', 'Stefon Diggs', 'Ed Oliver']
['Josh Allen', 'Stefon Diggs', 'Ed Oliver', 'Jordan Poyer']
['Josh Allen', 'Stefon Diggs', 'Ed Oliver']
Using the code provided, what will be the output for the print statements related to my_foods and friend_foods?
Which is an example of the proper use of the Python input() function?
What will be displayed on the Shell when the following statement runs: print("Have \n a great day.")?
In the process of program execution on a computer's CPU, high-level source code written by developers is eventually transformed to a format directly interpretable by the hardware. This final representation is called what?
In the early days of computer science, while machines like Charles Babbage's Analytical Engine were being conceptualized, one individual wrote notes on the engine that included what's recognized as the first computer algorithm. Who was this pioneering figure?
If x < 0: print("): else: if y >= 0: print(") else: print("-") Which values for x and y result in the output "+/-"? (Choose the best answer.)
There are three parameters in the slice method. What is the third parameter?
A list is an immutable object?
True
False
A description contains which of the following items? (choose all that apply). A short description of what the program does. A capitalized first letter. A period at the end. Pound sign.
What will be the output of the following code? def modify_list(lst): lst += [1, 2, 3] return lst data = [4, 5, 6] modify_list(data); print(data)
What is the result of the following code snippet? tuple1 = (1, 2, 3) tuple2 = (1, 2) print(tuple2 in tuple1)
(a)
What is the output of the above code? length = "33" length.isalnum() Choose the two best answers.
(a)
You're debugging a Python program that unexpectedly crashes when trying to perform arithmetic operations on two different data types. You identify that one of the data types is a string representing a decimal number. To resolve this, you decide to convert the string to another data type that supports decimal arithmetic. Which function would you use?
(a)
Testing for all Syntax Errors is called?
(a)
true and false are Boolean keywords in Python?
True
False
Is it possible to execute both the statements under an if and the else at the same time?
True
False
The first letter of a bool needs to be capitalized in Python.
True
False
Which line under the definition MUST be... built-in left-aligned bold Indented left-aligned
(a)
Which choice best represents the output of the following code? student_name = "iteration" new_word = for letter in student_name[:3]: new_word += letter print(new_word) iteration
Which of the following methods is used to count the occurrences of a specific element in a tuple?
(a)
Choose the correct statement.
Variables in Python can be initialized using the equals sign ( (a) ).
New variables always start out as (a) .
Anything passed in the () is called an __ or an __.
If we want to move items from one list to another what items below would we need to use to complete that task? (click all that apply)
Consider the list numbers = [5, 3, 9, 1]. After executing numbers.sort(), what will be the value of numbers[0]?
(a)
What is the output of the code below? print(10 > 9) print(10 == 9) print(10 < 9)
(a)
Modularization is breaking problems down into bigger and bigger problems until each one takes only a few steps to solve.
True
False
Python cannot display quotes in strings using print().
True
False
What is the output from running the above code snippet where year = "2001" if year.isdigit()?
What is the output when print(players[1:-1]) is used, given the list players = ['Von Miller', 'Josh Allen', 'Stefon Diggs', 'Ed Oliver', 'Jordan Poyer', 'Dawson Knox']?
Which contains only integers? (ignore the commas)
Imagine you are working with a Python script and you need to concatenate a number with a textual message. Which function would you use to ensure the number is treated as text during the concatenation?
The simplest way to match arguments in a function is with keyword arguments.
True
False
If you want to test more than one condition, what do you use after an IF statement?
not
elif
Testing for equality is case sensitive in Python.
True
False
Tuples support item assignment, allowing you to change the value of an element.
True
False
Always document (through remarks/comments) your code so you can remember what you are doing and so other programmers can follow the logic of the code.
True
False
In the for loop below, the variable "word" is an arbitrary variable name. Any valid variable name can be used since its value is assigned only within this loop. For letter in word: print(letter)
Print("Hello World!") will not output the message "Hello World!". What will it result in?
"Hello".isalpha() What is the output of the above code?
True
False
How would we say the following: car=="audi" Is the value of car equal to "audi"?
True
False
A string can be converted into numbers using multiple methods. Select all that apply below.
(a)
What is a tuple in Python?
True
False
Given x=9, which line of code will evaluate False? x = 9, x<=3, x<3, 3
The code below prints all numbers between 1 and 30 that are divisible by 5. for number in range(30): if number % 5 != 0: continue print(number, end=" ")
Which is a valid Python code comment?
Which of the following is not an advantage of using modules?
reducing the size of the program
Provides a means of
A collection of modules and packages that can be imported into a program is called a (a) .
What type of error is raised when you try to import a module that does not exist?
Choose the correct statement. A variable value in Python cannot be updated.
Which of the following methods can be used to obtain the length of a tuple?
If we want to combine a list with another list, we would use which method?
Which of the following statements are correct? (select at least 2 answers)
What is the result of trying to modify an element in a tuple?
How are elements accessed in a tuple?
Considering the tuple nums = (10, 20, 30, 40, 50, 60), what will nums[-3:-1] produce?
(a)
sales[3] = 1000 will place the item in the 2nd index.
True
False
Given the list fruits = ["apple", "banana", "cherry", "date", "elderberry"], what will fruits[1:4] return?
What is the output from running the above code using the following input at the "Enter an integer:" prompt? 1st input: 3, 2nd input: 4, 3rd input: five, 4th input: 6.
In computational arithmetic, which of the following operations yields the residue after the division of two integers, rather than the quotient?
(a)
What is the output from running the above code most like?
In Python, strings can contain only letters a-z and A-Z.
True
False
Which values for x and y result in the output "+-"? (Choose the best answer.)
x=0 and y=0
x=-1 and y=1
x=0 and y=-1
x=1 and y=0
An algorithm and pseudocode are the same thing.
True
False
Booleans have three (3) possible outcomes.
True
False
string.istitle() will return FALSE if the string is a title-cased string.
True
False
In python, we can use the "+" operator to add numbers, but not to add strings.
True
False
The nested conditional code is sure to run if _ (Choose the best answer.)
y=1
x=-1
x=1
y=-1
