如何解决如何解决第二个脚本虚线下方中的EOF问题?
此程序实质上是分别对消息和代码进行编码和解码。到目前为止,我只做过解码部分。但是,即使我确保结束括号,检查我的语法并不断对其进行篡改,我仍然收到EOF错误。不幸的是没有运气。有人知道为什么这个错误不断弹出吗?我将不胜感激。我也复制了我正在使用的两个文件。
from LetterCodeLogic import LCL
def main():
print("Welcome to the LetterCode program")
choice = getChoice()
while choice !=0:
if choice == 1:
#Encode logic...
print()
elif choice == 2:
#Decode logic...
msg = input("Enter your numbers to decode (separate with commas): ")
#send msg to Decode function in LCL class (LetterCodeLogic.py file)
result = LCL.Decode(msg)
print("Your decoded message is: \n" + result)
else:
print("Unknown process...")
print()
choice = getChoice()
print("Thanks for using the Letter Code program")
def getChoice():
c = int(input("Choice? (1=Encode,2=Decode,0=Quit): "))
return c
if __name__ == "__main__":
main()
class LCL:
"""Encode/Decode Functions"""
@staticmethod
def Decode(msg):
#separate numbers from msg string (e.g.,"1,2,3")
nums = msg.split(",") #produces list of separate items
result = ""
for x in nums:
try:
n = int(x.strip()) #remove leading/trailing spaces...
if n == 0:
c = " "
elif n < 0 or n > 26:
c = "?"
else:
#ASCII scheme has A=65,B=66,etc.
c = chr(n+64)
except ValueError:
c = "?"
result += c #same as: result = result + c
return result
@staticmethod
def Encode(msg):
解决方法
“ @ staticmethod”和“ def Encode()”函数为空,这是行解析错误的结尾。当我编码并运行它时,它没有问题。所以我暂时将其删除。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。