मराठी

We will try to read input from the user. Press Ctrl-d and see what happens: >>> s = raw_input('Enter something --> ')

Advertisements
Advertisements

प्रश्न

We will try to read input from the user. Press Ctrl-d and see what happens:

>>> s = raw_input('Enter something --> ')

कोड लेखन
Advertisements

उत्तर

In Python 2, pressing Ctrl-D sends an end-of-file signal. Since no input is supplied, raw_input() raises an EOFError exception. It can be handled as follows:

try:
    s = input("Enter something --> ")
except EOFError:
    print("End of input reached.")

In Windows, Ctrl-Z followed by Enter generally performs the equivalent EOF operation.

shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 8: Exception Handling & Generate Functions - EXERCISE [पृष्ठ १५६]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
पाठ 8 Exception Handling & Generate Functions
EXERCISE | Q 2. | पृष्ठ १५६
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×