提问人:sidereal 提问时间:10/26/2020 更新时间:10/26/2020 访问量:56
如何解决第二个脚本(虚线下方)中的EOF问题?
How can I fix EOF problem in the second script (below the dotted line)?
问:
该程序实质上分别对消息和代码进行编码和解码。到目前为止,我只做了解码部分。但是,即使我确保结束括号,检查我的语法并不断篡改它,我仍然收到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):
答:
0赞
sidereal
10/26/2020
#1
“@staticmethod”和“def Encode()”函数为空,这是行解析错误的结尾。当我对此进行编码并运行它时,它运行没有任何问题。所以我暂时删除了它。
评论
{}