- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
# String slicing
first = "John"
last = "Rambo"
username = first[0] + last[:7]
print(username, username.lower(), sep='\n' )
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
# Splitting a list
list1 = "ABC,ABC,ABC".split(",")
list2 = "ABCABCABC".split("B")
print( len(list1), list1[1] )
print( len(list2), list2[2] )
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
# Caesar Cipher
# chr('A') == 65
# chr('Z') == 90
plaintext = "BOX"
ciphertext = ""
key = 3
for ch in plaintext:
c = chr( ( ord(ch) - 65 + key ) % 26 + 65 )
ciphertext = ciphertext + c
print(ciphertext)