【发布时间】:2015-02-16 14:51:54
【问题描述】:
我的第一个问题是,当我输入 tex -10 时,除了 ValueError 不运行,只有第一个输入再次运行,但如果我输入 (-10),那么 ValuError 确实运行。我希望 ValueError 运行当我输入 -10 时,一个没有参数的负数
while True:
try:
number = int(input("Area?"))
if number>0:
break
except ValueError:
print("That was not a positive number") ##
我的第二个问题是,此功能仅在我有“a”时才有效,追加,而不是在我有 Write 时,有谁知道为什么,以及如何解决它?我想写一个文件。
def list_to_file():
file=open("file.txt","a")
file.write("\n")
file.write("".join(str(lista)))
【问题讨论】:
-
break不等于raise exception -
嗯,这不是代码重复吗?我可以用另一种方式解决整个问题,你不觉得吗? @TehTris
-
哦等等,我看看你在做什么......让我写一个答案......但是请在我写这个的时候更正你的空格。
标签: python file integer append