CBSE Class 11 Computer Science
Question 81 of 106
Python Fundamentals — Question 10
Back to all questions 10
Question Question 10
Consider the following code :
name = input ("What is your name?")
print ('Hi', name, ',')
print ("How are you doing?")was intended to print output as
Hi <name>, How are you doing ?
But it is printing the output as :
Hi <name>,
How are you doing?
What could be the problem ? Can you suggest the solution for the same ?
The print() function appends a newline character at the end of the line unless we give our own end argument. Due to this behaviour of print() function, the statement print ('Hi', name, ',1) is printing a newline at the end. Hence "How are you doing?" is getting printed on the next line.
To fix this we can add the end argument to the first print() function like this:
print ('Hi', name, ',1, end = '')