Font size
WorksheetsPython String Manipulation and Cipher Quiz
Total questions: 50
Worksheet time: 37mins
What is the purpose of variables in Python?
To store values
To define functions
To create loops
To handle errors
What does the assignment operator '=' do in Python?
Ends a statement
Compares two values
Assigns a value to a variable
Creates a function
What is the starting index of a string in Python?
(a)
What will the following code print: print(text[0]) if text = 'Hello'?
(a)
What does the len() function do?
Finds the index of a character
Checks if a string is alphabetic
Finds the length of a string
Converts a string to lowercase
What is the purpose of the .isalpha() method?
To check if a string is empty
To check if a string consists only of alphabet letters (a-z)
To find the length of a string
To convert a string to uppercase
What does the .find() method return?
The last character of a string
The index of the first occurrence of a character
A substring of the string
The length of the string
What is the main difference between the Caesar cipher and the Vigenère cipher?
Vigenère is simpler than Caesar
Caesar is more secure than Vigenère
Both use the same shifting method
Caesar uses a fixed shift, Vigenère uses a variable shift
What does the % operator do in the context of indexing?
Calculates the remainder
Converts a string to lowercase
Calculates the percentage
Checks if a character is alphabetic
What is the purpose of f-strings in Python?
To define loops
To format strings with variables
To handle exceptions
To create functions
name = 'Alice'
greeting = 'Hello'
What's the output of the following code:
print(greeting + ', ' + name + '!')
Hello, Alice!
Hello Alice!
Hello, Alice
Hello! Alice
What happens if the indentation is incorrect in Python?
The code runs without issues
Python throws an IndentationError
The code is ignored
The program crashes
What does the slice syntax text[start:end] do?
Checks if a string is alphabetic
Finds the length of a string
Converts a string to uppercase
Extracts a substring from a string
What is the output of the expression 'Hello'.upper() in Python?
HELLO
Hello
hello
H
my_string = 'Python'
What will be the output of:
print(my_string[-1])
Python
n
o
Error
What is the primary purpose of indentation in Python?
Indentation in Python is used to save memory. It means that you use less RAM.
Indentation in Python makes it look neat
Indentation in Python is used to define the structure. It shows which bits of code are linked together.
Indentation in Python makes the code run faster.
Which of the following is the correct indentation rule in Python?
Use two spaces for each level of indentation.
Use one tab for each level of indentation.
Do not use any indentation.
Use any amount of space, so long as you are consistent.
What symbol comes before an indented block in Python?
:
"
)
*
Which block(s) of code have indentation that will work?
Which block(s) of code have indentation that will work?
CORRECT indentation
WRONG indentation
CORRECT indentation
WRONG indentation
How to create a numeric variable age with a value of 10
age = 10
age = int(10)
age = "10"
How to insert comments in Python ?
# this is a comment
// this is a comment
/* this is a comment */
Which of the below operators can be used to compare two numbers
==
><
=
What will be the output of the following code?
print("Python"[1])
A) P
B) y
C) t
D) h
What letter will be printed on the screen after running this code:
e
x
t
Nothing prints
fruit1="kiwi"
fruit2="strawberry"
print(len(fruit1))
print(len(fruit2))
kiwi and strawberry
4
10
4 10
410
Slicing string
x="BOnvoyage"
print(x[4: ])
BOnvo
bonvo
oyage
VOYAGE
string = "Slartibartfast"
Which Python string method converts all the characters in string to upper case?
string.upper()
string.lower()
string.isalpha()
string.uppercase()
data = "No Way!"
The expression len(data) evaluates to:
6
7
8
9
print("12"*3)
What would this print?
121212
36
24
12*3
2
Error
convert (information or data) into a cipher or code, especially to prevent unauthorized access
Vigenere
Turing
decipher
encrypt
to decode or decipher
cipher
enigma machine
brute force
decrypt
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.
Vigenere
Caesar Cipher
CRIBS
cryptography
Which of the following options correctly defines the Brute force attack?
Brutally forcing the user to share the useful information like pins and passwords.
Trying every possible key to decrypt the message.
One entity pretends to be some other entity
The message or information is modified before sending it to the receiver.
Place comments onto the corresponding lines of code.
(a) are used to store (b) in Python. A variable is a (c) that references or points to an (d) .
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.
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.
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).
(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) ().
Inside the function, a block of code is (a) when the function is (b) . The result is returned using the (c) statement:
Match the following:
Caesar Cipher
a fixed shift for all characters
Vigenère Cipher
a variable shift that changes with a key
if-else statement
check conditions and execute code
for loop
iterate over sequences (strings, lists..
Which data type is used to store whole numbers in Python?
float
str
bool
int
Which keyword is used to display output in Python?
output
input
display
What is the syntax to check if two values are equal in Python?
==
=
is
===
What is the syntax to check if two values are not equal in Python?
!==
!=
==
<>
