python如何输入空行_在python中,如何在接受用户输入时跳过空行?
您得到的行為是預期的,請閱讀input文檔。在input([prompt])
If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised
嘗試這樣做,代碼將捕獲輸入函數可能產生的異常:if __name__ == "__main__":
tc = input("How many numbers you want:")
d = 0
while(tc != 0):
try:
num = input("Insert number:")
except Exception, e:
print "Error (try again),", str(e)
continue
i = 0
count = 0
for i in range(0, num):
try:
a = input("Insert number to add to your count:")
count = count + a
except Exception, e:
print "Error (count won't be increased),", str(e)
if (count % num == 0):
print 'YES'
else:
print 'NO'
tc = tc - 1
總結
以上是生活随笔為你收集整理的python如何输入空行_在python中,如何在接受用户输入时跳过空行?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 039_MySQL_多表查询
- 下一篇: 汉诺塔问题深度剖析(python实现)