Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What Error?!
#3
(02-10-2010, 08:22 AM)uber1337 Wrote: Common mistake, you overlooked a parentheses, you need to close them all.
Code:
ran = str(random.randrange(0, 1000, 1)
should be:
Code:
ran = str(random.randrange(0, 1000, 1))
If you don't close them all python looks at the next line to find it which happened to contain "rep", which is why you didn't know what to fix.

Edit:
Your code still has errors I can't really see what you are trying to do so I can't fix it for you but I can tell you what your doing wrong.
Code:
ran = str(random.randrange(0, 1000, 1)
        rep = string.replace(op1, op2, ran)
        xx = rep
        aa = [xx+xx**2, xx+xx**3, xx+xx**4, xx-xx**2, xx-xx**3, xx-xx**4, xx**2+xx**3, xx**2+xx**4, xx**2-xx**3, xx**2-xx**4, xx**3+xx**4, xx**3-xx**4]

Ok so basically the "**" can't be used with strings because if you think about it a string can't be raised to a power. Logically, 'hi' to the third power means 'hi' * 'hi' * 'hi', which makes no sense, if your looking just to multiply the words, just use "*", the result will be 'hihihi'.


Edit:
Also, you can't use "-" for strings, the only way to concatenate strings is with "+" and "*".
Thanks dude! I figured it out already; here is the code that actually works:
Code:
from __future__ import division
import string
import random
import os

while 1 > 0:
    def process(op1, op2):
        ran = random.randrange(0, 1000, 1)
        xx = ran
        aa = [xx+xx**2, xx+xx**3, xx+xx**4, xx-xx**2, xx-xx**3, xx-xx**4, xx**2+xx**3, xx**2+xx**4, xx**2-xx**3, xx**2-xx**4, xx**3+xx**4, xx**3-xx**4]
        start_1 = random.choice(aa)
        ee = start_1/4
        ex = str(ee)
        rr = string.replace(op1, op2, ex)
        return rr

    p = raw_input('>>> ')
    pp = string.join(p)
    os.system('clear')

    n_0 = process(pp, '0')
    n_1 = process(n_0, '1')
    n_2 = process(n_1, '2')
    n_3 = process(n_2, '3')
    n_4 = process(n_3, '4')
    n_5 = process(n_4, '5')
    n_6 = process(n_5, '6')
    n_7 = process(n_6, '7')
    n_8 = process(n_7, '8')
    n_9 = process(n_8, '9')
    a = process(n_9, 'a')    
    A = process(a, 'A')
    b = process(A, 'b')
    B = process(b, 'B')
    c = process(B, 'c')
    C = process(c, 'C')
    d = process(C, 'd')
    D = process(d, 'D')
    e = process(D, 'e')
    E = process(e, 'E')
    f = process(E, 'f')
    F = process(f, 'F')
    g = process(F, 'g')
    G = process(g, 'G')
    h = process(G, 'h')
    H = process(h, 'H')
    i = process(H, 'i')
    I = process(i, 'I')
    j = process(I, 'j')
    J = process(j, 'J')
    k = process(J, 'k')
    K = process(k, 'K')
    l = process(K, 'l')
    L = process(l, 'L')
    m = process(L, 'm')
    M = process(m, 'M')
    n = process(M, 'n')
    N = process(n, 'N')
    o = process(N, 'o')
    O = process(o, 'O')
    p = process(O, 'p')
    P = process(p, 'P')
    q = process(P, 'q')
    Q = process(q, 'Q')
    r = process(Q, 'r')
    R = process(r, 'R')
    s = process(R, 's')
    S = process(s, 'S')
    t = process(S, 't')
    T = process(t, 'T')
    u = process(T, 'u')
    U = process(u, 'U')
    v = process(U, 'v')
    V = process(v, 'V')
    w = process(V, 'w')
    W = process(w, 'W')
    x = process(W, 'x')
    X = process(x, 'X')
    y = process(X, 'y')
    Y = process(y, 'Y')
    z = process(Y, 'z')    
    Z = process(z, 'Z')
    a_ = process(Z, '.')
    a_1 = process(a_, '!')
    a_2 = process(a_1, '?')
    a_3 = process(a_2, ';')
    a_4 = process(a_3, ':')
    a_5 = process(a_4, "'")
    a_6 = process(a_5, '"')
    a_7 = process(a_6, '[')
    a_8 = process(a_7, "]")
    a_9 = process(a_8, '/')
    a_10 = process(a_9, '+')
    a_11 = process(a_10, '-')
    a_12 = process(a_11, ')')
    a_13 = process(a_12, '(')
    a_14 = process(a_13, '\\')

    r_ = string.replace(a_14, ' ', '$')
    r_0 = string.replace(r_, '-', '>')
    r_01 = string.replace(r_0, '.', '#')
    r_1 = string.replace(r_01, '1', '-Z')
    r_2 = string.replace(r_1, '2', '-Y')
    r_3 = string.replace(r_2, '3', '-X')
    r_4 = string.replace(r_3, '4', '+A')
    r_5 = string.replace(r_4, '5', '+B')
    r_6 = string.replace(r_5, '6', '+C')
    r_7 = string.replace(r_6, '7', '^z')
    r_8 = string.replace(r_7, '8', '^y')
    r_9 = string.replace(r_8, '9', '^x')
    r_0 = string.replace(r_9, '0', '_')
    
    print('\n'+r_0+'\n')
BTW, +1. You've always been helpful in the area of Python. :p

EDIT: BTW, this is only half of the project I'm doing. I have to make the decryption program now :/ If you want more details, please don't be afraid to ask!! :p
Do what thou wilt shall be the whole of the Law. Love is the law, love under will.
.::The Rights of Man::.
Reply


Messages In This Thread
What Error?! - by Canoris - 02-10-2010, 05:15 AM
RE: What Error?! - by uber1337 - 02-10-2010, 08:22 AM
RE: What Error?! - by Canoris - 02-10-2010, 02:52 PM
RE: What Error?! - by uber1337 - 02-10-2010, 03:09 PM
RE: What Error?! - by Canoris - 02-10-2010, 03:19 PM
RE: What Error?! - by uber1337 - 02-10-2010, 08:19 PM
RE: What Error?! - by Canoris - 02-11-2010, 05:29 AM
RE: What Error?! - by uber1337 - 02-11-2010, 08:30 AM
RE: What Error?! - by Canoris - 02-11-2010, 07:28 PM
RE: What Error?! - by uber1337 - 02-11-2010, 08:27 PM
RE: What Error?! - by Canoris - 02-12-2010, 01:46 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)