2014-11-03 236 views
1

這是一個程序,需要3位數字,存儲它們,並重復猜測和檢查,直到三個存儲的數字匹配3個猜測的數字。我似乎無法得到任何東西超過第一個while循環執行:爲什麼不執行此代碼?

digitone = int(raw_input()) 
digittwo = int(raw_input()) 
digitthree = int(raw_input()) 
digitthree = int(raw_input()) 
countdigitone = 0 
countdigittwo = 0 
countdigitthree = 0 

while digitone <= countdigitone: 
    if digitone < countdigitone: 
     print "Digit one could be", countdigitone 
     countdigitone += 1 
    elif digitone == countdigitone: 
     print "Digit one is", countdigitone 
     while digittwo <= countdigittwo: 
      if digittwo < countdigittwo: 
       print "The first two digits could be", countdigitone, countdigittwo 
       countdigittwo += 1 
      elif digittwo == countdigittwo: 
       print "Digits one and two are", countdigitone, countdigittwo 
       while digitthree <= countdigitthree: 
        if digitthree < countdigitthree: 
         print "The 3-digit number could be", countdigitone, countdigittwo, countdigitthree 
         countdigitthree += 1 
        elif digitthree == countdigitthree: 
         print "This is most definetly the number!", countdigitone, countdigittwo, countdigitthree 
         break 

它就在那裏。目前,它只需要你的號碼,打印單詞無,然後停下來。有沒有什麼辦法解決這一問題?

+5

您輸入的數字是否爲'digitone' <= 0?如果不是,那麼while循環不會執行。 – 2014-11-03 20:21:36

+0

你爲什麼要嵌套三個while循環?你爲什麼要問'digitthree'的價值兩次? – 2014-11-03 20:26:11

+0

@jgritty我看到我做了什麼。現在的問題是,這裏'countdigitone + = 1'我試圖增加'countdigitone'的數量。 – 2014-11-03 20:26:54

回答

0

while digitone <= countdigitone意味着除非digitone是一個負數它決不會小於countdigitone被設置爲0

我會做類似下面,循環,直到你找到每個數字的值,並在打印值結束:

digit_one = int(raw_input()) 
digit_two = int(raw_input()) 
digit_three= int(raw_input()) 
count_digit_one = 0 
count_digit_two = 0 
count_digit_three= 0 

while digit_one > count_digit_one: 
    print "Digit one could be", count_digit_one 
    count_digit_one += 1 

while digit_two > count_digit_two: 
    print "The first two digits could be", count_digit_one, count_digit_two 
    count_digit_two += 1 

while digit_three> count_digit_three: 
    print "The first three digits could be", count_digit_one, count_digit_two 
    count_digit_three += 1 
print "This is most definitely the number! {}{}{}".format(count_digit_one, count_digit_two, count_digit_three) 
0

第一個while循環做

while digitone <= countdigitone: 

你已經得到了digitone來自用戶。並且您已將countdigitone設置爲0.除非輸入的數字小於0,否則根本不會輸入while循環。