2016-07-30 54 views
1

我試圖寫一段代碼,根據國家彩票進行概率計算。 但我遇到了代碼運行方式的問題。
它每打印一次5次而不是創建一組新的隨機數,有人知道爲什麼嗎?隨機列表產生的塊不是單獨的行

gen = True 

while gen == True: 

#Generate Numbers 
a = random.randint(1,59) 
b = random.randint(1,59) 
c = random.randint(1,59) 
d = random.randint(1,59) 
e = random.randint(1,59) 
f = random.randint(1,59) 

#Create tickets as lists 
ticket = [] 
balls = [] 

#print the tickets 
for i in ticket: 
    g = ticket[0] 
    h = ticket[1] 
    i = ticket[2] 
    j = ticket[3] 
    k = ticket[4] 
    l = ticket[5] 

for i in balls: 
    m = balls[0] 
    n = balls[1] 
    o = balls[2] 
    p = balls[3] 
    q = balls[4] 
    r = balls[5] 


    print("TICKET") 
    print(g,h,i,j,k,l) 
    time.sleep(4) 
    print("BALLS") 
    print(m,n,o,p,q,r) 

謝謝任何​​人,不勝感激。

+0

你已經張貼不會打印任何東西,因爲'ticket'和'balls'是空列表的代碼。 – EngineerCamp

回答

0

我不確定我是否理解這個程序的目的,但是我看到你在第二個循環中打印了g,h,i,j,k,l變量,導致最後一個迭代值被打印爲相同的值。

如果目的是打印這些值,將車票打印在門票循環:

for i in ticket: 
    g = ticket[0] 
    h = ticket[1] 
    i = ticket[2] 
    j = ticket[3] 
    k = ticket[4] 
    l = ticket[5] 

    print("TICKET") 
    print(g,h,i,j,k,l) 

for i in balls: 
    m = balls[0] 
    n = balls[1] 
    o = balls[2] 
    p = balls[3] 
    q = balls[4] 
    r = balls[5] 


    print("BALLS") 
    print(m,n,o,p,q,r) 
+0

非常感謝您的解決方案,這非常有幫助。這只是該計劃的一部分,目的是查看在生成具有匹配號碼的票證之前必須創建多少次彩票。但謝謝你:) – Knowlesie