Contiuesly running input defined function

Question:

How can I make my code contiuesly running and keep asking for the user inputs and every time the input will be printed
Note: With while true I get the error EOFerror

 
 i = input()
 b = int(i,2)
    
 print (b)
Asked By: Firas Bayazed

||

Answers:

You can put your block under loop as following:

while True:
  c()

or like that:

def c():
  while True:
    i = input()
    b = int(i, 2)
    print(b)

Answered By: Kartikey

You can terminate your interactive input with Ctrl-D like this:

while True:
    try:
        n = input('Enter a binary number or Ctrl-D to end: ')
        x = int(n, 2)
        print(f'{n} = {x}')
    except EOFError:
        break
    except ValueError as e:
        print(e)
Answered By: Pingu
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.