variables - Error in python replace. (AttributeError: 'tuple' object has no attribute 'replace') -
environment
i using python 3 , os windows 7. understand commands have changed transition python 2.7 3 (what have used).
problem
the variable temporary this:
(((((0, 7), 7), 8), 4), 5)
here code rid of brackets:
randy = randy.replace(")", "") randy = randy.replace("(", "") randy = randy.replace(" ", "")
when tries execute replace function, thrown error:
traceback (most recent call last): file "<string>", line 248, in run_nodebug file "criptic.py", line 134, in <module> randy = randy.replace(")", "") attributeerror: 'tuple' object has no attribute 'replace'
edit:
here of code:
#import string import string import random #input user data text = input("enter text converted: ") #test print print("-------------------------") print("your text is: ",text) #break data data = list(text) #lowercase count = text.count("a") count1 = text.count("b") count2 = text.count("c") count3 = text.count("d") count4 = text.count("e") count5 = text.count("f") count6 = text.count("g") count7 = text.count("h") count8 = text.count("i") count9 = text.count("j") count10 = text.count("k") count11 = text.count("l") count12 = text.count("m") count13 = text.count("n") count14 = text.count("o") count15 = text.count("p") count16 = text.count("q") count17 = text.count("r") count18 = text.count("s") count19 = text.count("t") count20 = text.count("u") count21 = text.count("v") count22 = text.count("w") count23 = text.count("x") count24 = text.count("y") count25 = text.count("z") count26 = text.count("a") #uppercase count27 = text.count("b") count28 = text.count("c") count29 = text.count("d") count30 = text.count("e") count31 = text.count("f") count32 = text.count("g") count33 = text.count("h") count34 = text.count("i") count35 = text.count("j") count36 = text.count("k") count37 = text.count("l") count38 = text.count("m") count39 = text.count("n") count40 = text.count("o") count41 = text.count("p") count42 = text.count("q") count43 = text.count("r") count44 = text.count("s") count45 = text.count("t") count46 = text.count("u") count47 = text.count("v") count48 = text.count("w") count49 = text.count("x") count50 = text.count("y") count51 = text.count("z") #other characters count52 = text.count(" ") count53 = text.count("?") count54 = text.count("@") count55 = text.count("(") count56 = text.count(")") count57 = text.count(".") #numbers count58 = text.count("1") count59 = text.count("2") count60 = text.count("3") count61 = text.count("4") count62 = text.count("5") count63 = text.count("6") count64 = text.count("7") count65 = text.count("8") count66 = text.count("9") count67 = text.count("0") #counting how many characters in sentence finalcount = count + count1 + count2 + count3 + count4 + count5 + count6 + count7 + count8 + count9 + count10 + count11 + count12 + count13 + count14 + count15 + count16 + count17 + count18 + count19 + count20 + count21 + count22 + count23 + count24 + count25 + count26 + count27 + count28 + count29 + count31 + count32 + count33 + count34 + count35 + count36 + count37 + count38 + count39 + count40 + count41 + count42 + count43 + count44 + count45 + count46 + count47 + count48 + count49 + count50 + count51 + count52 + count53 + count54 + count55 + count56 + count57 + count58 + count59 + count60 + count61 + count62 + count63 + count64 + count65 + count66 + count67 #final count of characters print(" chars: ",finalcount) print("-------------------------") char = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz!@#$%^&*()?_+-=1234567890 " charnum = 74 + 11 list(char) randy = 0 num = 0 while num < finalcount: rand = random.randrange(1,9) randy = randy,rand finalcount = finalcount - 1 if rand == 1: print(text[finalcount],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],",") if rand == 2: print(char[random.randrange(0,charnum)],text[finalcount],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],",") if rand == 3: print(char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],text[finalcount],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],",") if rand == 4: print(char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],text[finalcount],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],",") if rand == 5: print(char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],text[finalcount],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],",") if rand == 6: print(char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],text[finalcount],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],",") if rand == 7: print(char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],text[finalcount],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],",") if rand == 8: print(char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],text[finalcount],char[random.randrange(0,charnum)],",") if rand == 9: print(char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],char[random.randrange(0,charnum)],text[finalcount],",") randy = randy.replace(")", "") randy = randy.replace("(", "") randy = randy.replace(" ", "") print("-------------------------") print("::::::::completed::::::::") print("-------------------------") print(randy) print("-this code unlock key. without code not decript!!!! ") print("-------------------------")
you have tuple (a sort of list) of numbers, , want make string. can't replace brackets, aren't part of variable, part of representation.
instead should use join()
, str()
result = " ".join(str(x) x in randy)
however, not give right result either, nested list of tuples. mean: randy = randy + (rand,)
instead if randy = randy,rand
.
Comments
Post a Comment