2013-05-05 4 views
-2

это мой полный код я не уверен, что проблемаполучение синтаксической ошибки в инструкции elif?

option = 0 

while option !=4: 

, прежде чем я повторял подобные коды по меню печати в пределах каждого выбора опции, но я изменил его от в то время как в случае и elif, но не работает?

# Prints the menu to the screen 


print("*** Menu *** \n") 
print("1. Encrypt string") 
print("2. Decrypt string") 
print("3. Brute force decryption") 
print("4. Quit \n") 

option = int(input("What would you like to do [1,2,3,4]? ")) 

* это та часть, где я использовал мое меню печати повторен код *

if option ==1: 
    print("In command 1 - encrypt string \n") 
    string = input("Please enter string to encrypt: ") 
    offsetvalue = int(input("Please enter positive offset value: ")) 
    print("") 

while offsetvalue > 26 or offsetvalue < 1: 
     offsetvalue = int(input("Please enter a positive offset value between 1 - 26: ")) 
     Encryption = "" 

for letter in string: 
    encryption_num = ord(letter) 
     encryption_num += offsetvalue 

**# Loops the ASCII value** 
if encryption_num > 126: 
     encryption_num -= 94 
     # adds it to the total string 
     encryption_num = chr(encryption_num) 
     Encryption += encryption_num 
     # encrypted string to the screen 
     print("\nEncrypted string:") 
     print(Encryption) 

elif option == 2: 

     # prompts the user to input 
     print("In command 2 - decrypt string \n") 
     string = input("Please enter string to decrypt: ") 
     offsetvalue = int(input("Please enter negative offset value: ")) 
     print("") 

while offsetvalue < -26 or offsetvalue > -1: 
     offsetvalue = int(input("Please enter negative offset value between -1 - -26: ")) 

    Decryption = "" 

for letter in string: 
    decryption_num = ord(letter) 
    decryption_num += offsetvalue 
     if decryption_num < 32: 
      decryption_num += 94 
      decryption_num = chr(decryption_num) 
      Decryption += decryption_num 

      print("\nDecrypted string:") 
      print(Decryption) 

проблема, кажется, здесь

elif option == 3: 
    print("in command 3 -brute force \n") 
    string = input("please enter string to decrypt: ") 
    offsetvalue = -0 
    while offsetvalue != -26: 
    decryption_num = 0 
    Decryption = "" 

while Decryption < len(letter): 
     c = ord(string[decryption_num]) + offsetvalue 
     if c < 0: 
     c += 128 
     decryption_num = chr(c) 
     Decryption += decryption_str 
     decryption_num += 1 
     offsetvalue -= 1 
     print ("\noffset", offsetvalue, "=Decrypted string:", Decryption) 


    option = int(input("What would you like to do [1,2,3,4]? ")) 

#input error 
elif option == 4: 
     print ("\nGoodbye") 

Я старался изо всех сил, чтобы не конечно, где проблема - любая помощь будет оценена ....

+2

Можете ли вы опубликовать * точное * сообщение об ошибке? Существуют различные типы синтаксических ошибок. – poke

+1

Можете ли вы также опубликовать код перед состоянием 'elif'? –

+0

И вы также можете убедиться, что отступы в размещенном коде соответствуют вашему исходному коду? – poke

ответ

2

Это нет особого смысла:

elif option == 3: 
     print("in command 3 -brute force \n") 
     string = input("please enter string to decrypt: ") 
     offsetvalue = -0 
    while offsetvalue != -26: 

Именно этот

elif option == 3: 
     print("in command 3 -brute force \n") 
     string = input("please enter string to decrypt: ") 
     offsetvalue = -0 
     while offsetvalue != -26: 

или что

elif option == 3: 
     print("in command 3 -brute force \n") 
     string = input("please enter string to decrypt: ") 
     offsetvalue = -0 
while offsetvalue != -26: 
+0

да я изменил его @peterMmm – legend

+0

любой лучше я отправил код while с правильным отступом @PeterMmm – legend

Смежные вопросы