What will be the output of the following Python code? (If entered name is 123hoidap) [code] import sys print 'Enter your name: ', name

What will be the output of the following Python code? (If entered name is 123hoidap)
Code:
import sys
print 'Enter your name: ',
name = ''
while True:
   c = sys.stdin.read(1)
   if c == '\n':
      break
   name = name + c
print 'Your name is:', name
A. 123hoidap
B. 123hoidap, 123hoidap
C. San
D. None of the mentioned
 
Answer: a
Explanation: In order to work with standard I/O streams, we must import the sys module. The read() method reads one character from the standard input. In our example we get a prompt saying “Enter your name”. We enter our name and press enter. The enter key generates the new line character: \n.
Output:
Enter your name: 123hoidap
Your name is: 123hoidap
 

Tìm kiếm

Back
Top