Read numbers till eof and show squares : Console Read : Development PYTHON examples


PYTHON examples » Development » Console Read »

 

Read numbers till eof and show squares


Read numbers till eof and show squares




def interact():
    print 'Hello stream world'                      # print sends to sys.stdout
    while 1:
        try:
            reply  = raw_input('Enter a number>')   # raw_input reads sys.stdin
        except EOFError:
            break                                   # raises an except on eof
        else:                                       # input given as a string
            num = int(reply)
            print "%d squared is %d" (num, num ** 2)
    print 'Bye'

if __name__ == '__main__': 
    interact()                                      # when run, not imported

           
       



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo Development
» Console Read