[英]How can I get rid of AttributeError problem?
当我将 python 文件上传到 codePost.io 时,我收到一条错误消息,显示“读取一行时出现 EOF 错误”。 我尝试使用“try and except”方法,但在这种情况下,我得到了一个 AttributeError。 我应该怎么办? 这是我的代码:
try:
rows = int(input("Enter a number of rows: "))
columns = int(input("Enter a number of columns: "))
def print_rect(row, col):
for r in range(1, row + 1):
for i in range(1, col + 1):
if r == 1 or r == row or i == 1 or i == col:
print("*", end="")
else:
print(" ", end="")
print()
print_rect(rows, columns)
except EOFError:
pass
请试试这个:
try:
print("Enter a number of rows:")
rows = int(input())
print("Enter a number of columns:")
columns = int(input())
def print_rect(row, col):
for r in range(1, row + 1):
for i in range(1, col + 1):
if r == 1 or r == row or i == 1 or i == col:
print("*", end="")
else:
print(" ", end="")
print()
print_rect(rows, columns)
except EOFError:
pass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.