Computer Science
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 , How are you doing ?
But it is printing the output as:
Hi ,
How are you doing?
What could be the problem ? Can you suggest the solution for the same ?
Python Funda
38 Likes
Answer
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 = '')
Answered By
29 Likes
Related Questions
Find the errors in following code fragment:
a = input("value") b = a/2 print (a, b)
Find the errors in following code fragment : (The input entered is XI)
c = int (input ( "Enter your class") ) print ("Your class is", c)
Find the errors in following code fragment :
c = input( "Enter your class" ) print ("Last year you were in class") c - 1
What will be returned by Python as result of following statements?
(a) >>> type(0)
(b) >>> type(int(0))
(c) >>>.type(int('0')
(d) >>> type('0')
(e) >>> type(1.0)
(f) >>> type(int(1.0))
(g) >>>type(float(0))
(h) >>> type(float(1.0))
(i) >>> type( 3/2)