I'm working on a website called NOWCODER, similar to the Leetcode but a Chinese version.
One of the question is asking for user to input some text(multiple lines) and determine whether the texts that enter are qualified as an appropriate password.
What bothers me is the input()
so I write my code on Jupyter notebook (python 3) as:
# 1st Code
s = [] # get all the input text
while True:
try:
lines = input()
if lines:
s.append(lines)
else:
break
the code works fine in jupyter nootbook but when i copied it to the nowcoder website it doesn't work, it said "no input and output data"
so i modified the code to the following:
# 2nd Code
s = []
while True:
try:
s.append(input())
except:
break
and it works
The problem is now I tried to execute the 2nd Code in the Jupyter notebook, the while loop never ends and keeps asking for input. I don't know how to fix it or where is the problem.
Also i try re.stdin.readline()
and it doenst work on jupyter nootbook, so I want to know if there is some way to make it executable on both the NOWCODER website as well as on the Jupyter notebook