[英]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.