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)
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)
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)
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)
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)
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)