Re: [閒聊] Python高手請進

看板Marginalman作者 (a十個Q)時間7年前 (2018/04/28 23:18), 編輯推噓3(304)
留言7則, 6人參與, 7年前最新討論串1/1
import random def compare_numbers(number, user_guess): cowbull = [0,0] for i in range(len(number)): if number[i] == user_guess[i]: cowbull[1]+=1 else: cowbull[0]+=1 return cowbull if __name__=="__main__": playing = True number = str(random.randint(0,9999)) #random 4 digit number guesses = 0 user_guess = input("Give me your best guess!") if user_guess == "exit": break cowbullcount = compare_numbers(number,user_guess) guesses+=1 print(str(cowbullcount[0])+"A" + str(cowbullcount[1]) + "B") if cowbullcount[1]==4: playing = False print("You win the game after " + str(guesses) + "guess!" print("The number was "+str(number)) break else: print("Try again.") ※ 引述《shiburin (希布凜)》之銘言: : 你好 : 我有個人還不錯的同學遇到了一點困難 : 就是要完成Bull and Cows的程式 : https://imgur.com/tasVRQb
: 但是我不太會寫 : 請問有沒有人願意用Python寫 : 站內信,給稅後800P : 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.217.42 ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1524928682.A.BEB.html

04/28 23:18, 7年前 , 1F
工具人?
04/28 23:18, 1F

04/28 23:20, 7年前 , 2F
112
04/28 23:20, 2F

04/28 23:21, 7年前 , 3F
雪花喵喵紅包預備
04/28 23:21, 3F

04/28 23:23, 7年前 , 4F
A9=Angel=彥州?
04/28 23:23, 4F

04/28 23:24, 7年前 , 5F
這爛學吧 呿 結果還是不肯露宿網ip
04/28 23:24, 5F

04/28 23:24, 7年前 , 6F
04/28 23:24, 6F

04/28 23:26, 7年前 , 7F
幾A幾B不是位置數字正確 / 位置錯誤、數字正確嗎?
04/28 23:26, 7F
文章代碼(AID): #1Qv92glh (Marginalman)