dimanche 17 septembre 2017

If / else statement not working depending on random number (Python)

I'm making a text encrypt-er that randomizes the pattern of symbols used (abcd) but after the first if statement, the program no longer works. New, old, get , and tag are the 4 letter to symbol translations. I tested out only the first if statement by itself and it worked perfectly fine. Also any tips in how to shorten the code would be much appreciated.

our_str = input("Mornin' ")
length = (len(our_str)/2)
rounded = round(length)
import random
rand = random.randint(1,6)
print(rand)
if rand <= 2: #abcd
    new_str = our_str[:rounded].replace('a', ']')
    new1_str = new_str.replace('b', '◙')
    new2_str = new1_str.replace('c', '♂')
    new3_str = new2_str.replace('d', 'd')
    new4_str = new3_str.replace('e', 'e')
    new5_str = new4_str.replace('f', '▓')
    new6_str = new5_str.replace('g', '─')
    new7_str = new6_str.replace('h', 'Φ')
    new8_str = new7_str.replace('i', 'Θ')
    new9_str = new8_str.replace('j', '≥')
    new10_str = new9_str.replace('k', '≤')
    new11_str = new10_str.replace('l', 'L')
    new12_str = new11_str.replace('m', 'M')
    new13_str = new12_str.replace('n', 'V')
    new14_str = new13_str.replace('o', 'W')
    new15_str = new14_str.replace('p', '►')
    new16_str = new15_str.replace('q', '◄')
    new17_str = new16_str.replace('r', '→')
    new18_str = new17_str.replace('s', '←')
    new19_str = new18_str.replace('t', 't')
    new20_str = new19_str.replace('u', 'u')
    new21_str = new20_str.replace('v', '~')
    new22_str = new21_str.replace('w', '⌂')
    new23_str = new22_str.replace('x', '°')
    new24_str = new23_str.replace('y', '∙')
    new25_str = new24_str.replace('z', '☻')
    new26_str = new25_str.replace(' ', 'f')
    old_str = our_str[rounded:2 * rounded].replace('a', 'Y')
    old1_str = old_str.replace('b', 'É')
    old2_str = old1_str.replace('c', 'Θ')
    old3_str = old2_str.replace('d', '╩')
    old4_str = old3_str.replace('e', 'b')
    old5_str = old4_str.replace('f', '█')
    old6_str = old5_str.replace('g', '=')
    old7_str = old6_str.replace('h', '↑')
    old8_str = old7_str.replace('i', 'U')
    old9_str = old8_str.replace('j', '⌂')
    old10_str = old9_str.replace('k', '┬')
    old11_str = old10_str.replace('l', 'æ')
    old12_str = old11_str.replace('m', '◄')
    old13_str = old12_str.replace('n', '1')
    old14_str = old13_str.replace('o', 'B')
    old15_str = old14_str.replace('p', 'Ñ')
    old16_str = old15_str.replace('q', '╡')
    old17_str = old16_str.replace('r', '▌')
    old18_str = old17_str.replace('s', '♣')
    old19_str = old18_str.replace('t', 'Γ')
    old20_str = old19_str.replace('u', 'τ')
    old21_str = old20_str.replace('v', '╔')
    old22_str = old21_str.replace('w', '░')
    old23_str = old22_str.replace('x', '┘')
    old24_str = old23_str.replace('y', 'ó')
    old25_str = old24_str.replace('z', ';')
    old26_str = old25_str.replace(' ', 'ß')
    get_str = our_str[2 * rounded:3 * rounded].replace('a', 'ç')
    get1_str = get_str.replace('b', '1')
    get2_str = get1_str.replace('c', '♣')
    get3_str = get2_str.replace('d', 'ⁿ')
    get4_str = get3_str.replace('e', '♠')
    get5_str = get4_str.replace('f', 'S')
    get6_str = get5_str.replace('g', '°')
    get7_str = get6_str.replace('h', '♫')
    get8_str = get7_str.replace('i', 'D')
    get9_str = get8_str.replace('j', '│')
    get10_str = get9_str.replace('k', '←')
    get11_str = get10_str.replace('l', 'ƒ')
    get12_str = get11_str.replace('m', 'Æ')
    get13_str = get12_str.replace('n', 'P')
    get14_str = get13_str.replace('o', '#') #skipped 0781, 6406
    get15_str = get14_str.replace('p', '.') #0899
    get16_str = get15_str.replace('q', '┤') #0348
    get17_str = get16_str.replace('r', 'µ')
    get18_str = get17_str.replace('s', 'E')
    get19_str = get19_str.replace('t', '§')
    get20_str = get20_str.replace('u', '▬')
    get21_str = get21_str.replace('v', 'û')
    get22_str = get22_str.replace('w', '♀')
    get23_str = get23_str.replace('x', '&')
    get24_str = get24_str.replace('y', '≈')
    get25_str = get25_str.replace('z', 'ª') #4460
    get26_str = get26_str.replace(' ', 'N')
    tag_str = our_str[3 * rounded:].replace('a', '╬')
    tag1_str = tag_str.replace('b', '↓')
    tag2_str = tag1_str.replace('c', '<')
    tag3_str = tag2_str.replace('d', '╦')
    tag4_str = tag3_str.replace('e', '-')
    tag5_str = tag4_str.replace('f', 'δ') #skipped 360
    tag6_str = tag5_str.replace('g', '▼')
    tag7_str = tag6_str.replace('h', '╫')
    tag8_str = tag7_str.replace('i', '`')
    tag9_str = tag8_str.replace('j', 'û')
    tag10_str = tag9_str.replace('k', '±')
    tag11_str = tag10_str.replace('l', '⌡')
    tag12_str = tag11_str.replace('m', '≈')
    tag13_str = tag12_str.replace('n', ']')
    tag14_str = tag13_str.replace('o', '╗')
    tag15_str = tag14_str.replace('p', '┐')
    tag16_str = tag15_str.replace('q', '>')
    tag17_str = tag16_str.replace('r', '╞')
    tag18_str = tag17_str.replace('s', '╟') #627
    tag19_str = tag18_str.replace('t', '╘')
    tag20_str = tag19_str.replace('u', 'L')
    tag21_str = tag20_str.replace('v', 'v') #353
    tag22_str = tag21_str.replace('w', '#')
    tag23_str = tag22_str.replace('x', 'R')
    tag24_str = tag23_str.replace('y', ';')
    tag25_str = tag24_str.replace('z', '~')
    tag26_str = tag25_str.replace(' ', '▓')
    print(new26_str + old26_str + get26_str + tag26_str)
elif 2 < rand <= 4 #abdc
    new_str = our_str[:rounded].replace('a', ']')
    new1_str = new_str.replace('b', '◙')
    new2_str = new1_str.replace('c', '♂')
    new3_str = new2_str.replace('d', 'd')
    new4_str = new3_str.replace('e', 'e')
    new5_str = new4_str.replace('f', '▓')
    new6_str = new5_str.replace('g', '─')
    new7_str = new6_str.replace('h', 'Φ')
    new8_str = new7_str.replace('i', 'Θ')
    new9_str = new8_str.replace('j', '≥')
    new10_str = new9_str.replace('k', '≤')
    new11_str = new10_str.replace('l', 'L')
    new12_str = new11_str.replace('m', 'M')
    new13_str = new12_str.replace('n', 'V')
    new14_str = new13_str.replace('o', 'W')
    new15_str = new14_str.replace('p', '►')
    new16_str = new15_str.replace('q', '◄')
    new17_str = new16_str.replace('r', '→')
    new18_str = new17_str.replace('s', '←')
    new19_str = new18_str.replace('t', 't')
    new20_str = new19_str.replace('u', 'u')
    new21_str = new20_str.replace('v', '~')
    new22_str = new21_str.replace('w', '⌂')
    new23_str = new22_str.replace('x', '°')
    new24_str = new23_str.replace('y', '∙')
    new25_str = new24_str.replace('z', '☻')
    new26_str = new25_str.replace(' ', 'f')
    old_str = our_str[rounded:2 * rounded].replace('a', 'Y')
    old1_str = old_str.replace('b', 'É')
    old2_str = old1_str.replace('c', 'Θ')
    old3_str = old2_str.replace('d', '╩')
    old4_str = old3_str.replace('e', 'b')
    old5_str = old4_str.replace('f', '█')
    old6_str = old5_str.replace('g', '=')
    old7_str = old6_str.replace('h', '↑')
    old8_str = old7_str.replace('i', 'U')
    old9_str = old8_str.replace('j', '⌂')
    old10_str = old9_str.replace('k', '┬')
    old11_str = old10_str.replace('l', 'æ')
    old12_str = old11_str.replace('m', '◄')
    old13_str = old12_str.replace('n', '1')
    old14_str = old13_str.replace('o', 'B')
    old15_str = old14_str.replace('p', 'Ñ')
    old16_str = old15_str.replace('q', '╡')
    old17_str = old16_str.replace('r', '▌')
    old18_str = old17_str.replace('s', '♣')
    old19_str = old18_str.replace('t', 'Γ')
    old20_str = old19_str.replace('u', 'τ')
    old21_str = old20_str.replace('v', '╔')
    old22_str = old21_str.replace('w', '░')
    old23_str = old22_str.replace('x', '┘')
    old24_str = old23_str.replace('y', 'ó')
    old25_str = old24_str.replace('z', ';')
    old26_str = old25_str.replace(' ', 'ß')
    get_str = our_str[3 * rounded:].replace('a', 'ç')
    get1_str = get_str.replace('b', '1')
    get2_str = get1_str.replace('c', '♣')
    get3_str = get2_str.replace('d', 'ⁿ')
    get4_str = get3_str.replace('e', '♠')
    get5_str = get4_str.replace('f', 'S')
    get6_str = get5_str.replace('g', '°')
    get7_str = get6_str.replace('h', '♫')
    get8_str = get7_str.replace('i', 'D')
    get9_str = get8_str.replace('j', '│')
    get10_str = get9_str.replace('k', '←')
    get11_str = get10_str.replace('l', 'ƒ')
    get12_str = get11_str.replace('m', 'Æ')
    get13_str = get12_str.replace('n', 'P')
    get14_str = get13_str.replace('o', '#') #skipped 0781, 6406
    get15_str = get14_str.replace('p', '.') #0899
    get16_str = get15_str.replace('q', '┤') #0348
    get17_str = get16_str.replace('r', 'µ')
    get18_str = get17_str.replace('s', 'E')
    get19_str = get19_str.replace('t', '§')
    get20_str = get20_str.replace('u', '▬')
    get21_str = get21_str.replace('v', 'û')
    get22_str = get22_str.replace('w', '♀')
    get23_str = get23_str.replace('x', '&')
    get24_str = get24_str.replace('y', '≈')
    get25_str = get25_str.replace('z', 'ª') #4460
    get26_str = get26_str.replace(' ', 'N')
    tag_str = our_str[2 * rounded: 3 * rounded].replace('a', '╬')
    tag1_str = tag_str.replace('b', '↓')
    tag2_str = tag1_str.replace('c', '<')
    tag3_str = tag2_str.replace('d', '╦')
    tag4_str = tag3_str.replace('e', '-')
    tag5_str = tag4_str.replace('f', 'δ') #skipped 360
    tag6_str = tag5_str.replace('g', '▼')
    tag7_str = tag6_str.replace('h', '╫')
    tag8_str = tag7_str.replace('i', '`')
    tag9_str = tag8_str.replace('j', 'û')
    tag10_str = tag9_str.replace('k', '±')
    tag11_str = tag10_str.replace('l', '⌡')
    tag12_str = tag11_str.replace('m', '≈')
    tag13_str = tag12_str.replace('n', ']')
    tag14_str = tag13_str.replace('o', '╗')
    tag15_str = tag14_str.replace('p', '┐')
    tag16_str = tag15_str.replace('q', '>')
    tag17_str = tag16_str.replace('r', '╞')
    tag18_str = tag17_str.replace('s', '╟') #627
    tag19_str = tag18_str.replace('t', '╘')
    tag20_str = tag19_str.replace('u', 'L')
    tag21_str = tag20_str.replace('v', 'v') #353
    tag22_str = tag21_str.replace('w', '#')
    tag23_str = tag22_str.replace('x', 'R')
    tag24_str = tag23_str.replace('y', ';')
    tag25_str = tag24_str.replace('z', '~')
    tag26_str = tag25_str.replace(' ', '▓')
    print(new26_str + old26_str + tag26_str + get26_str)
hi = input("Bye")

P.S - The hi input is to not let the Python console close.




Aucun commentaire:

Enregistrer un commentaire