2017-02-16 67 views
-3

我對Python很新,我試圖寫「餅乾」(不是真的,只是一個程序,寫所有可能的組合)。試圖寫「餅乾」 - OFC它不工作,但我認爲它可以xD

我用linecache,然後只是while循環(太多)。

當時的想法是,以與AZ和0-9字符的字典,然後使用linecache獲得字符,並把它們一起

(它的工作,只有2個字符變化,但是當我試圖爲8個字符... )

,因爲我新的Python我是不是真的有intendation的朋友,但不知何故,我做到了工作,但...

問題是,它永遠不會做:

print("ITS HERE") 

................................................ ................................

import easygui 
import time 
import linecache 



x1=1 
x2=1 
x3=1 
x4=1 
x5=1 
x6=1 
x7=1 
x8=0 
p=0 

while p!=36: 
p=p+1 
while x1!=36: 
    while x2!=36: 
     while x3!=36: 
      while x4!=36: 
       while x5!=36: 
        while x6!=36: 
         while x7!=36: 

          while x8!=36: 
           x8=x8+1 

           Char1=linecache.getline("Dictionary.txt",x1).rstrip("\n") 
           Char2=linecache.getline("Dictionary.txt",x2).rstrip("\n") 
           Char3=linecache.getline("Dictionary.txt",x3).rstrip("\n") 
           Char4=linecache.getline("Dictionary.txt",x4).rstrip("\n") 
           Char5=linecache.getline("Dictionary.txt",x5).rstrip("\n") 
           Char6=linecache.getline("Dictionary.txt",x6).rstrip("\n") 
           Char7=linecache.getline("Dictionary.txt",x7).rstrip("\n") 
           Char8=linecache.getline("Dictionary.txt",x8).rstrip("\n") 
           print(Char1+Char2+Char3+Char4+Char5+Char6+Char7+Char8) 
           time.sleep(0.25) 


           if x2==36: 
            x1=x1+1 
            x2=0 
           if x3==36: 
            x2=x2+1 
            x3=0 
           if x4==36: 
            x3=x3+1 
            x4=0 


           if x5==36: 
            x4=x4+1 
            x5=0 
           if x6==36: 
            x5=x5+1 
            x6=0 
           if x7==36: 
            x6=x6+1 
            x7=0 
           if x8==36: 
            x7=x7+1 
            x8=0 






time.sleep (60000) 
+0

除非我失去了一些東西,36的8次方四(0.25秒的睡眠)劃分爲8000千年的最壞情況。也就是說,'x7'在'while x7!= 36:'內永遠不會改變,這是一個無限循環。我推薦[官方Python教程](https://docs.python.org/3.6/tutorial/index.html)。 – TigerhawkT3

+0

如何?它看起來不錯,我在半天看它,它必須是奇蹟,或只是比我更有經驗的人的幫助 – CandyKing

+1

除非你真的想讓它變得緩慢低效,否則請看itertools.permutations。 –

回答

0

所以這裏是工作代碼,如果你有千禧一代時間definetely嘗試吧XD

import easygui 
import time 
import linecache 



x1=1 
x2=1 
x3=1 
x4=1 
x5=1 
x6=1 
x7=1 
x8=1 


while x8!=36: 


    Char1=linecache.getline("AlgoDictionary.txt",x1).rstrip("\n") 
    Char2=linecache.getline("AlgoDictionary.txt",x2).rstrip("\n") 
    Char3=linecache.getline("AlgoDictionary.txt",x3).rstrip("\n") 
    Char4=linecache.getline("AlgoDictionary.txt",x4).rstrip("\n") 
    Char5=linecache.getline("AlgoDictionary.txt",x5).rstrip("\n") 
    Char6=linecache.getline("AlgoDictionary.txt",x6).rstrip("\n") 
    Char7=linecache.getline("AlgoDictionary.txt",x7).rstrip("\n") 
    Char8=linecache.getline("AlgoDictionary.txt",x8).rstrip("\n") 
    print(Char1+Char2+Char3+Char4+Char5+Char6+Char7+Char8) 
    time.sleep (0.1) 
    x8=x8+1        

    if x2==36: 
     x1=x1+1 
     x2=1 
    if x3==36: 
     x2=x2+1 
     x3=1 
    if x4==36: 
     x3=x3+1 
     x4=1 
    if x5==36: 
     x4=x4+1 
     x5=1 
    if x6==36: 
     x5=x5+1 
     x6=1 
    if x7==36: 
     x6=x6+1 
     x7=1 
    if x8==36: 
     x7=x7+1 
     x8=1 
相關問題