Jun-19-2020, 07:19 AM
Hi All,
Please could someone help with the error I am getting with my code
Description
Change each character of an list into different characters. Below is the sample example:
u became y,
p became t,
G became K,
r became v,
a became e,
d became h,
Please could someone help with the error I am getting with my code
Description
Change each character of an list into different characters. Below is the sample example:
u became y,
p became t,
G became K,
r became v,
a became e,
d became h,
Output:Input
['banana', 7]
Solution output
ihuhuh
Expected output
utgtgt
Input
['ytKveh', 4]
Solution output
cxOzil
Expected output
upGrad
Sorry posted wrong code and error!!!!also just to let you know what need to be altered in the code to get the desired output.#take input on your own #start writing your code from here import ast mylist=ast.literal_eval(input()) stringMessage=mylist[0] shift_value=mylist[1] def swap_letters(word, step_count): final_word = "" for x in list(word): # for lowercase letters crossing the Ascii values if(ord(x)+step_count>122 and ord(x)>97): w = ((ord(x)+step_count)-122)+96 y = chr(w) final_word = final_word + y # for lowercase letters crossing the Ascii values elif(ord(x)+step_count>91 and ord(x)<91): w = ((ord(x)+step_count)-90)+64 y = chr(w) final_word = final_word + y # for normal letters within the Std Ascii Values else: y = chr(ord(x)+step_count) final_word = final_word + y return final_word print(swap_letters(stringMessage,shift_value))OK, I'm really new to python can anyone help me to correct the code