wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Programming Quiz

Total questions: 95

Worksheet time: 3hrs 38mins

Name
Class
Date
1.

What is the output of this code snippet where x=4 and then x is set to "Sally"?

4 lines
2.

Which is an example of Python string addition that will run without error?

a)

Hello" + "World!"

b)

new_string = Hello + World! All choices message1 'Hello' + 'World!'

c)

message1 = 'Hello' + 'World!'

3.

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?

a)

True

b)

False

4.

The string.isdigit() does what?

a)

Returns True if all characters in the string are lowercase

b)

Returns True if the string is a title-cased string otherwise returns False

c)

Returns True if all characters are alphabetical or digits

5.

In Python, you can use the in operator to check if a value exists in a group of values.

a)

True

b)

False

6.

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?

4 lines
7.

Using the following list of players, what will be the output when print(players[1:5]) is used?

4 lines
8.

What value is stored in the "total" variable after the following code runs: for i in range(1,5): total = total + i?

4 lines
9.

In Python, what is the maximum number of parameters a function can accept?

4 lines
10.

Choose the statement that will print the letter "O", given the variable declaration word "MACBOOK"

a)

print(word[-1])

b)

print(word[3])

c)

print(word[2])

d)

print(word[-2])

11.

Which of the following are characteristics of tuples in Python? (Select all that apply) Tuples can contain elements of different data types

a)

Tuples are ordered

b)

Tuples support item assignment

c)

Tuples are mutable

d)

Tuples can contain elements of different data types

12.

print("It's time to code") What is the output of the above code?

4 lines
13.

The while loop takes a collection of items and executes a block of code once for each item in the collection. False

4 lines
14.

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

4 lines
15.

How can you create a tuple with a single element?

a)

(element)

b)

(element.)

c)

element

d)

(element)

e)

(element,)

16.

Which of the following is not a valid operation on tuples?

a)

Modifying an element at a specific index

b)

Finding the length using the len() function

c)

Concatenation using the + operator

d)

Accessing elements by index

17.

What does the Python code: score = 3 + "45" result in?

4 lines
18.

What is the output of this code? x = 5 y = "John" print(x) print(y)

4 lines
19.

Which of the following operations are supported by tuples in Python? (Select all that apply)

a)

Slicing using the [] operator

b)

Appending elements using the append() method

c)

Repetition using the * operator

d)

Concatenation using the + operator

20.

Using the list fruits ("apple", "banana", "cherry"), how would you add "orange" to the end?

a)

fruits.append("orange")

b)

fruits add("orange")

c)

fruits push("orange")

d)

fruits.put("orange")

21.

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?

4 lines
22.

What is the output from running the following code? x=0 while x < 5: x += 1 print("loop")

4 lines
23.

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?

a)

No output

b)

time is 3

c)

time is 4

24.

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?

a)

Assembly Language

b)

Python

c)

Java

d)

C++

25.

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?

a)

players.pop(2)

b)

players.remove(2)

c)

players.delete(2)

d)

players.cut(2)

26.

What is the output when print(players[1:4]) is used?

a)

['Josh Allen', 'Stefon Diggs', 'Ed Oliver']

b)

['Josh Allen', 'Stefon Diggs', 'Ed Oliver', 'Jordan Poyer']

c)

['Josh Allen', 'Stefon Diggs', 'Ed Oliver']

27.

Using the code provided, what will be the output for the print statements related to my_foods and friend_foods?

4 lines
28.

Which is an example of the proper use of the Python input() function?

4 lines
29.

What will be displayed on the Shell when the following statement runs: print("Have \n a great day.")?

4 lines
30.

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?

4 lines
31.

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?

4 lines
32.

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.)

4 lines
33.

There are three parameters in the slice method. What is the third parameter?

4 lines
34.

A list is an immutable object?

a)

True

b)

False

35.

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.

4 lines
36.

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)

4 lines
37.

What is the result of the following code snippet? tuple1 = (1, 2, 3) tuple2 = (1, 2) print(tuple2 in tuple1)

(a)  

38.

What is the output of the above code? length = "33" length.isalnum() Choose the two best answers.

(a)  

39.

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)  

40.

Testing for all Syntax Errors is called?

(a)  

41.

true and false are Boolean keywords in Python?

a)

True

b)

False

42.

Is it possible to execute both the statements under an if and the else at the same time?

a)

True

b)

False

43.

The first letter of a bool needs to be capitalized in Python.

a)

True

b)

False

44.

Which line under the definition MUST be... built-in left-aligned bold Indented left-aligned

(a)  

45.

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

4 lines
46.

Which of the following methods is used to count the occurrences of a specific element in a tuple?

(a)  

47.

Choose the correct statement.

4 lines
48.

Variables in Python can be initialized using the equals sign ( (a)   ).

49.

New variables always start out as (a)   .

50.

Anything passed in the () is called an __ or an __.

4 lines
51.

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)

4 lines
52.

Consider the list numbers = [5, 3, 9, 1]. After executing numbers.sort(), what will be the value of numbers[0]?

(a)  

53.

What is the output of the code below? print(10 > 9) print(10 == 9) print(10 < 9)

(a)  

54.

Modularization is breaking problems down into bigger and bigger problems until each one takes only a few steps to solve.

a)

True

b)

False

55.

Python cannot display quotes in strings using print().

a)

True

b)

False

56.

What is the output from running the above code snippet where year = "2001" if year.isdigit()?

4 lines
57.

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']?

4 lines
58.

Which contains only integers? (ignore the commas)

4 lines
59.

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?

4 lines
60.

The simplest way to match arguments in a function is with keyword arguments.

a)

True

b)

False

61.

If you want to test more than one condition, what do you use after an IF statement?

a)

not

b)

elif

62.

Testing for equality is case sensitive in Python.

a)

True

b)

False

63.

Tuples support item assignment, allowing you to change the value of an element.

a)

True

b)

False

64.

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.

a)

True

b)

False

65.

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)

4 lines
66.

Print("Hello World!") will not output the message "Hello World!". What will it result in?

4 lines
67.

"Hello".isalpha() What is the output of the above code?

a)

True

b)

False

68.

How would we say the following: car=="audi" Is the value of car equal to "audi"?

a)

True

b)

False

69.

A string can be converted into numbers using multiple methods. Select all that apply below.

(a)  

70.

What is a tuple in Python?

a)

True

b)

False

71.

Given x=9, which line of code will evaluate False? x = 9, x<=3, x<3, 3

4 lines
72.

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=" ")

4 lines
73.

Which is a valid Python code comment?

4 lines
74.

Which of the following is not an advantage of using modules?

a)

reducing the size of the program

b)

Provides a means of

75.

A collection of modules and packages that can be imported into a program is called a (a)   .

76.

What type of error is raised when you try to import a module that does not exist?

4 lines
77.

Choose the correct statement. A variable value in Python cannot be updated.

4 lines
78.

Which of the following methods can be used to obtain the length of a tuple?

4 lines
79.

If we want to combine a list with another list, we would use which method?

4 lines
80.

Which of the following statements are correct? (select at least 2 answers)

4 lines
81.

What is the result of trying to modify an element in a tuple?

4 lines
82.

How are elements accessed in a tuple?

4 lines
83.

Considering the tuple nums = (10, 20, 30, 40, 50, 60), what will nums[-3:-1] produce?

(a)  

84.

sales[3] = 1000 will place the item in the 2nd index.

a)

True

b)

False

85.

Given the list fruits = ["apple", "banana", "cherry", "date", "elderberry"], what will fruits[1:4] return?

4 lines
86.

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.

4 lines
87.

In computational arithmetic, which of the following operations yields the residue after the division of two integers, rather than the quotient?

(a)  

88.

What is the output from running the above code most like?

4 lines
89.

In Python, strings can contain only letters a-z and A-Z.

a)

True

b)

False

90.

Which values for x and y result in the output "+-"? (Choose the best answer.)

a)

x=0 and y=0

b)

x=-1 and y=1

c)

x=0 and y=-1

d)

x=1 and y=0

91.

An algorithm and pseudocode are the same thing.

a)

True

b)

False

92.

Booleans have three (3) possible outcomes.

a)

True

b)

False

93.

string.istitle() will return FALSE if the string is a title-cased string.

a)

True

b)

False

94.

In python, we can use the "+" operator to add numbers, but not to add strings.

a)

True

b)

False

95.

The nested conditional code is sure to run if _ (Choose the best answer.)

a)

y=1

b)

x=-1

c)

x=1

d)

y=-1