wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python String Manipulation and Cipher Quiz

Total questions: 50

Worksheet time: 37mins

Name
Class
Date
1.

What is the purpose of variables in Python?

a)

To store values

b)

To define functions

c)

To create loops

d)

To handle errors

2.

What does the assignment operator '=' do in Python?

a)

Ends a statement

b)

Compares two values

c)

Assigns a value to a variable

d)

Creates a function

3.

What is the starting index of a string in Python?

(a)  

4.

What will the following code print: print(text[0]) if text = 'Hello'?

(a)  

5.

What does the len() function do?

a)

Finds the index of a character

b)

Checks if a string is alphabetic

c)

Finds the length of a string

d)

Converts a string to lowercase

6.

What is the purpose of the .isalpha() method?

a)

To check if a string is empty

b)

To check if a string consists only of alphabet letters (a-z)

c)

To find the length of a string

d)

To convert a string to uppercase

7.

What does the .find() method return?

a)

The last character of a string

b)

The index of the first occurrence of a character

c)

A substring of the string

d)

The length of the string

8.

What is the main difference between the Caesar cipher and the Vigenère cipher?

a)

Vigenère is simpler than Caesar

b)

Caesar is more secure than Vigenère

c)

Both use the same shifting method

d)

Caesar uses a fixed shift, Vigenère uses a variable shift

9.

What does the % operator do in the context of indexing?

a)

Calculates the remainder

b)

Converts a string to lowercase

c)

Calculates the percentage

d)

Checks if a character is alphabetic

10.

What is the purpose of f-strings in Python?

a)

To define loops

b)

To format strings with variables

c)

To handle exceptions

d)

To create functions

11.

name = 'Alice'

greeting = 'Hello'


What's the output of the following code:
print(greeting + ', ' + name + '!')

a)

Hello, Alice!

b)

Hello Alice!

c)

Hello, Alice

d)

Hello! Alice

12.

What happens if the indentation is incorrect in Python?

a)

The code runs without issues

b)

Python throws an IndentationError

c)

The code is ignored

d)

The program crashes

13.

What does the slice syntax text[start:end] do?

a)

Checks if a string is alphabetic

b)

Finds the length of a string

c)

Converts a string to uppercase

d)

Extracts a substring from a string

14.

What is the output of the expression 'Hello'.upper() in Python?

a)

HELLO

b)

Hello

c)

hello

d)

H

15.

my_string = 'Python'
What will be the output of:
print(my_string[-1])

a)

Python

b)

n

c)

o

d)

Error

16.

What is the primary purpose of indentation in Python?

a)

Indentation in Python is used to save memory. It means that you use less RAM.

b)

Indentation in Python makes it look neat

c)

Indentation in Python is used to define the structure. It shows which bits of code are linked together.

d)

Indentation in Python makes the code run faster.

17.

Which of the following is the correct indentation rule in Python?

a)

Use two spaces for each level of indentation.

b)

Use one tab for each level of indentation.

c)

Do not use any indentation.

d)

Use any amount of space, so long as you are consistent.

18.

What symbol comes before an indented block in Python?

a)

:

b)

"

c)

)

d)

*

19.

Which block(s) of code have indentation that will work?

a)

b)

c)

d)

20.

Which block(s) of code have indentation that will work?

a)

b)

c)

d)

21.

a)

CORRECT indentation

b)

WRONG indentation

22.

a)

CORRECT indentation

b)

WRONG indentation

23.

How to create a numeric variable age with a value of 10

a)

age = 10

b)

age = int(10)

c)

age = "10"

24.

How to insert comments in Python ?

a)

# this is a comment

b)

// this is a comment

c)

/* this is a comment */

25.

Which of the below operators can be used to compare two numbers

a)

==

b)

><

c)

=

26.

What will be the output of the following code?
print("Python"[1])

a)

A) P

b)

B) y

c)

C) t

d)

D) h

27.

What letter will be printed on the screen after running this code:

a)

e

b)

x

c)

t

d)

Nothing prints

28.

fruit1="kiwi"

fruit2="strawberry"

print(len(fruit1))

print(len(fruit2))

a)

kiwi and strawberry

b)

4

10

c)

4 10

d)

410

29.

Slicing string

x="BOnvoyage"

print(x[4: ])

a)

BOnvo

b)

bonvo

c)

oyage

d)

VOYAGE

30.

string = "Slartibartfast"

Which Python string method converts all the characters in string to upper case?

a)

string.upper()

b)

string.lower()

c)

string.isalpha()

d)

string.uppercase()

31.

data = "No Way!"
The expression len(data) evaluates to:

a)

6

b)

7

c)

8

d)

9

32.

print("12"*3)

What would this print?

a)

121212

b)

36

c)

24

d)

12*3

33.
What output will this code produce?
a)
1
b)
3
c)
2
d)
4
34.
What output will this code produce?
a)
3
b)
20
c)

2

d)

Error

35.

convert (information or data) into a cipher or code, especially to prevent unauthorized access

a)

Vigenere

b)

Turing

c)

decipher

d)

encrypt

36.

to decode or decipher

a)

cipher

b)

enigma machine

c)

brute force

d)

decrypt

37.

A substitution cipher where each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet.
For example, with a left shift of 3, D would be replaced by A, E would become B, and so on.
The method is named after a Roman Imperor.

a)

Vigenere

b)

Caesar Cipher

c)

CRIBS

d)

cryptography

38.

Which of the following options correctly defines the Brute force attack?

a)

Brutally forcing the user to share the useful information like pins and passwords.

b)

Trying every possible key to decrypt the message.

c)

One entity pretends to be some other entity

d)

The message or information is modified before sending it to the receiver.

39.

Place comments onto the corresponding lines of code.

40.

​ (a)   are used to store ​ (b)   in Python. A variable is a ​ (c)   that references or points to an ​ (d)   .

Choose from the below words
Variables
values
name
object
insert
functions
arrays
41.

You can ​ (a)   a variable by writing the ​ (b)   on the ​ (c)   of the ​ (d)   = and specifying the ​ (e)   to assign to that variable on the right side of the assignment operator.

Choose from the below words
declare
left side
variable name
assignment operator
value
expression
delete
top side
42.

Indentation in ​ (a)   is crucial because it defines ​ (b)   . Unlike many other languages that use ​ (c)   {} to delimit blocks, Python uses ​ (d)   (usually 4 ​ (e)   ) to group statements.

Choose from the below words
curly braces
indentation
blocks of code
spaces
Python
tabs
commas
43.

A string in Python is a ​ (a)   of (b)   enclosed in ​ (c)   , either single ('...') or double ("..."). Strings are one of the most commonly used (d)   . Strings are (e)   (once created, they cannot be changed).

Choose from the below words
characters
data types
immutable
quotes
sequence
numbers
mutable
44.

​ (a)   are blocks of ​ (b)   code that perform a specific task. In Python, functions are defined using the ​ (c)   keyword followed by the function ​ (d)   and ​ (e)   ().

Choose from the below words
Functions
reusable
def
name
parentheses
variables
loops
classes
45.

Inside the function, a block of code is ​ (a)   when the function is ​ (b)   . The result is returned using the ​ (c)   statement:

Choose from the below words
called
return
executed
ignored
print
skipped
46.

Match the following:

a)

Caesar Cipher

1.

a fixed shift for all characters

b)
  • Vigenère Cipher

2.
  • a variable shift that changes with a key

c)

if-else statement

3.

check conditions and execute code

d)
  • for loop

4.
  • iterate over sequences (strings, lists..

47.

Which data type is used to store whole numbers in Python?

a)

float

b)

str

c)

bool

d)

int

48.

Which keyword is used to display output in Python?

a)

output

b)

input

c)

print

d)

display

49.

What is the syntax to check if two values are equal in Python?

a)

==

b)

=

c)

is

d)

===

50.

What is the syntax to check if two values are not equal in Python?

a)

!==

b)

!=

c)

==

d)

<>