Printing a string with variables inside another string

You want to also create a duplicate copy of the message for your records, that is clearly marked as the teacher's copy. What is the output if we try to put the string inside another string?

1
2
3
4
5
6
name = 'Aditya'
score = 98

message = "Hi %s. You achieved a score of %d." % (name, score)

print "Teacher's Copy: %s" % message

Teacher's Copy: "Hi Aditya. You achieved a score of 98 in the class." Teacher's Copy: Hi Aditya. You achieved a score of 98 in the class. TypeError: 'str' object is not callable Teacher's Copy: 'Hi Aditya. You achieved a score of 98 in the class.'

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Tom Engelsman
Oct 19, 2020

Hello, Sue! I had no idea you actually wrote some Brilliant problems :) Thanks for posting!!

Saurab Thakur
Jul 5, 2014

Clearly the variable message is also a string (its callable) so the pointer first point to print "Teacher's Copy: %s" % message - then it goes to messege - message = "Hi %s. You achieved a score of %d." % (name, score) then it has to get to name and score and then jumps back to print So we get our answer : Teacher's Copy: Hi Aditya. You achieved a score of 98 in the class.

The correct answer is wrong. You have "in the class" after the score and you haven't typed that into the string "message"

Amanda Hogan - 6 years, 10 months ago

Log in to reply

Yeah I too think the same

vivek arora - 6 years, 10 months ago

the same I was thinking. There is no correct answer in given options

Anubha Agrawal - 6 years, 4 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...