PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 30, 2022

[FIXED] How to scan an unknown number of numbers in Python?

 October 30, 2022     eof, python     No comments   

Issue

Is there a way to scan an unknown number of elements in Python (I mean scan numbers until the user writes at the standard input eof(end of file))?


Solution

raw_input (input in Python 3) throws EOFError once EOF is reached.

while 1:
    try:
        num = int(raw_input("enter a number: "))
    except EOFError:
        break


Answered By - nneonneo
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing