LearnFrenzy
Sign in Take a free test

Strings · Find the Error · Question 5

Bug: the name is not converted to capitals Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

The program should print the name in capitals. Which statement correctly identifies the bug?

main.py
name = "meera"
name.upper()
print("Welcome,", name)
  • A upper() only works on single letters
  • B print should use an f-string
  • C upper() returns a new string, and its result is thrown away; write name = name.upper() Correct
  • D name must be declared as str
Correct Answer: Option C

Strings are immutable; every string method returns a new value that must be stored.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links