2017-09-02 27 views
-1

我想計算一個輸入數字的數量,例如四位數字4256,我怎麼知道有多少四,二,五和六。我會查找隨機數中的數字數量。 編輯: 我繼續工作,這就是我得到的。爲重複問題提出道歉。 進口隨機如何計算輸入中的數字量?

import random 

guess = random.randint(1000,9999) 
guess = str(guess) 
correct = 0 

print(guess) #this was only here for testing 

number = input("Enter ") 
list(number) 

if number[0] in guess: 
    correct = correct + 1 
    print (correct) 
+1

有幾種不同的方式做什麼你問。你能否展示一下你試過的東西? –

+0

尋找一個副本... –

+0

'collections.Counter(input())'? – MSeifert

回答

-1

要計數x多少次出現在Y,使用

Z = y.count(x)的

相關問題