Reputation: 21
At the end of my program, I want the following text to be displayed on the user's screen: "Thanks [StudentName] for participating in the quiz." StudentName
is the variable with the name of the student (a string).
Here is the single line of code which I attempted to use to achieve this: print("Thanks", StudentName)
. I'm missing the part "for participating in the quiz" after the student name. What command do I have to input to get this part printed?
Upvotes: 0
Views: 71
Reputation: 9624
print("Thanks", StudentName, "for participating in the quiz.")
or
# will only work if studetName is a string
# if it's an int for a really weird reason it will throw a TypeError
print("Thanks " + studentName + " for participating in the quiz." )
or
print("Thanks {} for participating in the quiz.".format(StudentName))
or
print "Thanks %s for participating in the quiz." % studentName #python2
There are several ways to format and print strings in python but the new str.format()
is the most flexible and in my opinion is easier to read
Upvotes: 2
Reputation: 149853
You want str.format()
:
print("Thanks {} for participating in the quiz.".format(StudentName))
Upvotes: 1