生成随机字符串并在python中匹配它们

时间:2017-04-14 05:13:10

标签: python-3.x random

这是一个python程序,用于生成随机字符串并将其与用户给定的输出进行匹配,并获得计算机尝试次数的返回但我无法获得尝试次数  随机导入

class txt:

  def __init__(self):
        self.txt = None
        trycount = 0

  def maketxt(self,txt):
        txt = ""
        a = []
        a.append(txt.split())
       # return a

#  def match(self):
        tokenlist = ["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"]
        matchlist =[]
        while (len(matchlist) <=24):
              x =random.choice(tokenlist)
              matchlist.append(x)
        if matchlist == a:
              print(trycount)
        else :

              trycount += 1
              match()

t = txt()
t.maketxt( “hagjkrshgujrahg”) 我一直在收到错误 文件“C:/ Users / ##### / AppData / Local / Programs / Python / Python36 / test1.py”,第25行,在maketxt中     trycount + = 1 UnboundLocalError:赋值前引用的局部变量'trycount'

0 个答案:

没有答案
相关问题