Question
how do i indent this code so it runs smooth? string = input(Enter (brief) text to encrypt:) shift = int(input(Enter the number to shift letters
how do i indent this code so it runs smooth?
string = input("Enter (brief) text to encrypt:") shift = int(input("Enter the number to shift letters by: ")) shift = shift%26 st = "" # stores the encrypted string for i in string: od = ord(i) # ascii value of alphabet # ignore the encryption of ' ' or space if od != 32: if od>=97 and od <=122: # converts small letters to capital (97 - 122 are ASCII value of a-z) od -= 32 od += shift # shift the ascii value by shift number if od>90: st += chr(65 + (od - 90)-1) else: st += chr(od) else: st += i # simply add ' ' or space to the encrypted string return st except: print("ERROR") home()
def decode(): # if any error occurs in the try, redirect the interpreter to the 'home' funcion try: string = input("Enter (brief) text to decrypt: ") shift = int(input("Enter the number to shift letters by: ")) shift = shift%26 st = "" # stores the decrypted string for i in string: od = ord(i) # ascii value of alphabet # ignore the decryption of ' ' or space if od!=32: if od>=97 and od <=122: # converts small letters to capital od -= 32 od -= shift # shift the ascii value by shift number if od<65: st += chr(90 - (65 - od) + 1) else: st += chr(od) else: st += i # simply add ' ' or space to the encrypted string return st except: print("ERROR") home()
def home(): # execute while loop until 'Q' is not pressed as input while (1): print("MAIN MENU:") print("1) Encode a sting") print("2) Decode a sting") print("Q) Quit") sel = str(input("Enter your selection ==> ")) if sel == '1': # call 'encode' function and print the output output = encode() print("Encrypted:",output) elif sel == '2': # call 'decode' function and print the output output = decode() print("Decrypted:",output) elif sel == 'Q': # quit the program break else: # shows the message and go to the starting of the home function print("Please select any of the option") home()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started