【发布时间】:2015-11-10 02:30:22
【问题描述】:
我的代码的输出应该是这样的:
加密:
Enter 1 to encipher or 2 to decipher: 1
Enter text you wish to encipher: My dog has fleas.
Enter the number of characters to shift: 7
The encrypted text is: Fr whz atl yextl.
解密:
Enter 1 to encipher or 2 to decipher: 2
Enter text you wish to decipher: Fr whz atl yextl.
The most likely shift is: 7
My dog has fleas.
到目前为止,我有这个并且我不断收到无效的语法。我对如何在输出中输入答案感到困惑。它应该是尝试/除一个while循环,因为它是一个学校作业。
while True:
try:
num = int(raw_input('Enter 1 or 2:'))
if num in [1,2]:
break
print "You have to enter 1 or 2, try again"
if (num == 1):
num = int(raw_input('Enter a number:'))
num = int(raw_input('encipher'))
print "Enter text to encipher"
print "Enter the number of characters you want to shift"
elif (num == 2):
num = int(raw_input('Enter a number:'))
num = int(raw_input('decipher'))
print "Enter text to decipher"
print "Enter the number of characters you want to shift"
【问题讨论】:
-
这是您在程序中使用的缩进吗?
-
是的。我刚开始使用 python,缩进让我很困惑。
标签: python try-catch except try-except