Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc stands for End Of File. Well, technically it is not an error, rather an exception. This exception is raised when one of the built-in functions, most commonly input[] returns End-Of-File [EOF] without reading any data.
Bàn luận
- EOF là viết tắt của kết thúc tập tin. Vâng, về mặt kỹ thuật, nó không phải là một lỗi, thay vào đó là một ngoại lệ. Ngoại lệ này được nêu ra khi một trong các hàm tích hợp, thường là đầu vào [] trả về phần cuối [EOF] mà không cần đọc bất kỳ dữ liệu nào.
- Lỗi EOF được nêu trong Python trong một số kịch bản cụ thể:input[] function is interrupted in both Python 2.7 and Python 3.6+, or when the input[] reaches the end of a file unexpectedly in Python 2.7.
Đôi khi tất cả các chương trình cố gắng làm là lấy một cái gì đó và sửa đổi nó. Nhưng khi nó không thể tìm nạp, nó sẽ tăng ngoại lệ này.BaseExceptionclass or extend from an inherited class therein. The full exception hierarchy of this error is:
Khi hàm input [] bị gián đoạn trong cả Python 2.7 và Python 3.6+ hoặc khi đầu vào [] đạt đến phần cuối của tệp bất ngờ trong Python 2.7.
Tất cả các trường hợp ngoại lệ tích hợp trong Python kế thừa từ baseexceptionClass hoặc mở rộng từ một lớp được thừa hưởng trong đó. Phân cấp ngoại lệ đầy đủ của lỗi này là:EOF in python while coding on any platform is to catch the exception, and we don’t need to perform any action so, we just pass the exception using the keyword “pass” in the “except” block.
Baseexception -> Ngoại lệ -> Eoferror
C++
#Python program for the above question
#Function to reorder the characters
#of the string
def main[]:
t =
int
[input[]]
Cách thực hành tốt nhất để tránh EOF trong Python trong khi mã hóa trên bất kỳ nền tảng nào là nắm bắt ngoại lệ và chúng tôi không cần phải thực hiện bất kỳ hành động nào, vì vậy, chúng tôi chỉ cần vượt qua ngoại lệ bằng cách sử dụng từ khóa vượt qua trên đường trừ, ngoại trừ.
Hãy xem xét mã sau cho câu hỏi trong chuỗi có thể nạp Codechef K [Kold]:
#Function to reorder the characters
1#Function to reorder the characters
4int
#Function to reorder the characters
6
#Function to reorder the characters
1#Function to reorder the characters
8
#Function to reorder the characters
1#of the string
0#of the string
1
#Function to reorder the characters
1#of the string
3
#Function to reorder the characters
1#of the string
5
while
#Function to reorder the characters
0
#of the string
9def main[]:
0
#Function to reorder the characters
1def main[]:
2
#Function to reorder the characters
1def main[]:
4def main[]:
5def main[]:
6
#Function to reorder the characters
1def main[]:
8def main[]:
9def main[]:
6
#Function to reorder the characters
1
2
#Function to reorder the characters
1
4
5def main[]:
5
7def main[]:
9
9
#Function to reorder the characters
1t =
1def main[]:
5t =
3def main[]:
9t =
5
#of the string
9#of the string
0t =
8
#Function to reorder the characters
1int
0
#Function to reorder the characters
1#Function to reorder the characters
2
#of the string
9int
5def main[]:
9int
7def main[]:
5int
9
#of the string
9int
5def main[]:
5[input[]]
3def main[]:
9[input[]]
5
#of the string
9[input[]]
7
#of the string
9[input[]]
9
#Function to reorder the characters
1
1
#Function to reorder the characters
1
3
#Function to reorder the characters
1
5
#Function to reorder the characters
1
7
9
while
0
#Function to reorder the characters
1#of the string
7 #of the string
8
while
6
Output:
#Function to reorder the characters
1int
2int
3EOF error as shown below:
4 while
2while
3int
3EOF error is to enclose the code in try and except blockand deal with exception accordingly, the approach to handle
this exception is shown below:
C++
while
7
while
8
#of the string
Nó cho lỗi EOF như hình dưới đây:
#Function to reorder the characters
05
Cách thực hành tốt nhất để tránh EOF trong Python trong khi mã hóa trên bất kỳ nền tảng nào là nắm bắt ngoại lệ và chúng tôi không cần phải thực hiện bất kỳ hành động nào, vì vậy, chúng tôi chỉ cần vượt qua ngoại lệ bằng cách sử dụng từ khóa vượt qua trên đường trừ, ngoại trừ.
#Function to reorder the characters
1#Function to reorder the characters
10
#Function to reorder the characters
1#Function to reorder the characters
4int
#Function to reorder the characters
6
#Function to reorder the characters
1#Function to reorder the characters
8
#Function to reorder the characters
1#of the string
0#of the string
1
#Function to reorder the characters
1#of the string
3
#Function to reorder the characters
1#of the string
5
while
#Function to reorder the characters
0
#of the string
9def main[]:
0
#Function to reorder the characters
1def main[]:
2
#Function to reorder the characters
1def main[]:
4def main[]:
5def main[]:
6
#Function to reorder the characters
1def main[]:
8def main[]:
9def main[]:
6
#Function to reorder the characters
1
2
#Function to reorder the characters
1
4
5def main[]:
5
7def main[]:
9#Function to reorder the characters
47
#Function to reorder the characters
1t =
1def main[]:
5t =
3def main[]:
9t =
5
#of the string
9#of the string
0t =
8
#Function to reorder the characters
1int
0
#Function to reorder the characters
1int
2int
3
#of the string
9int
5def main[]:
9int
7def main[]:
5int
9
#of the string
9int
5def main[]:
5[input[]]
3def main[]:
9[input[]]
5
#of the string
9[input[]]
7
#of the string
9[input[]]
9
#Function to reorder the characters
1
1
#Function to reorder the characters
1
3
#Function to reorder the characters
1
5
#Function to reorder the characters
1#Function to reorder the characters
2
#Function to reorder the characters
86
#Function to reorder the characters
88
Output: