The program below stops with an error. Which statement correctly describes the problem?
word = "python"
print("Last letter:", word[len(word)])
A 6-character string has indexes 0–5. word[-1] is the idiomatic last character.
Strings · Exercise 3 of 4
Each Python program has a string mistake: a syntax error, an exception at run time, or a logical bug such as testing find() with if. Choose the option that names the real problem.
The program below stops with an error. Which statement correctly describes the problem?
word = "python"
print("Last letter:", word[len(word)])
A 6-character string has indexes 0–5. word[-1] is the idiomatic last character.
The program below stops with an error. Which statement correctly describes the problem?
otp_digits = [4, 8, 2, 1]
print("OTP:", "".join(otp_digits))
join is a str method and every item must already be a str.
The program below stops with an error. Which statement correctly describes the problem?
email = "ravi.learnfrenzy.com"
at = email.index("@")
print("User:", email[:at])
The address has no @. find() would return -1 instead – and email[:-1] would then silently give the wrong result, so check first.
Python refuses to run the program below. Which statement correctly describes the problem?
print("She said "hello" to me")
Write 'She said "hello" to me' or "She said \"hello\" to me".
The program should print the name in capitals. Which statement correctly identifies the bug?
name = "meera"
name.upper()
print("Welcome,", name)
Strings are immutable; every string method returns a new value that must be stored.
The text starts with "python", yet the program reports it as missing. Which statement correctly identifies the bug?
text = "python rocks"
if text.find("python"):
print("found")
else:
print("not found")
Never use find() as a boolean. Use in, or compare: text.find("python") != -1.
The sentence has 3 words, but the program counts 6. Which statement correctly identifies the bug?
sentence = "Learn Python daily"
words = sentence.split(" ")
print("Words:", len(words))
"a b".split(" ") gives ['a', '', '', 'b']. split() treats any run of whitespace as one separator.
"Madam" should be reported as a palindrome. Which statement correctly identifies the bug?
word = "Madam"
if word == word[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Normalise first: w = word.lower(); w == w[::-1].
The program below stops with an error. Which statement correctly describes the problem?
code = "LF"
code.append("2026")
print(code)
append belongs to list. For strings, concatenate and rebind.
The program below stops with an error. Which statement correctly describes the problem?
width = 30 / 2
print("=" * width)
/ always gives a float. // (or int()) gives the int that repetition needs.
Timed online tests with instant scores and explanations.