navgurukul / newton

Includes all our curriculum for all the courses.
https://merakilearn.org/
GNU General Public License v3.0
26 stars 81 forks source link

Python debugging part3 debugging question3 #123

Open utterances-bot opened 4 years ago

utterances-bot commented 4 years ago

Python debugging part3 debugging question3

http://saral.navgurukul.org/api/course?id=18

RajuSonwani commented 4 years ago

def find_in_list(query, mainlist): mainlist_len = len(chars) range_for_loop = range(mainlist_len) for i in range_for_loop: element = mainlist[i] if element== query: index = i break return i

chars = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] shifted_chars = ['c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b']

def encrypt_message(plain_msg): encrypted_msg="" for character in plain_msg: if character in chars: char_index = find_in_list(character, chars) new_char = shifted_chars[char_index] encrypted_msg = encrypted_msg + new_char else: encrypted_msg = encrypted_msg + character return encrypted_msg

def decrypt_message(encrypted_msg): decrypted_msg="" for character in encrypted_msg: if character in shifted_chars: char_index = find_in_list(character, shifted_chars) new_char = chars[char_index] decrypted_msg = decrypted_msg + new_char else: decrypted_msg = decrypted_msg + character return decrypted_msg

flag = True while flag == True: choice = input("What do you want to do? 1. Encrypt a message 2. Decrypt a message Enter e or d respectively!") if choice =='e': plain_message = input("Enter message to encrypt??") print(encrypt_message(plain_message)) elif choice =='d': encrypted_msg = input("Enter message to decrypt?") print(decrypt_message(encrypted_msg)) flag*=False else: flag=True while flag==True: play_again = input("Do you want to try agian or Do you want to exit? (Y/N)") if play_again == 'Y': choice =input("What do you want to do? 1. Encrypt a message 2. Decrypt a message Enter e or d respectively!") if choice =='e': plain_message = input("Enter message to encrypt??") print(encrypt_message(plain_message)) elif choice =='d': encrypted_msg = input("Enter message to decrypt?") print(decrypt_message(encrypted_msg)) elif play_again == 'N': print("exit") break ........................................................... i did it.

abhishekgupta92 commented 4 years ago

Don't post solutions :-)