2014-09-10 25 views
-3
print "You've entered a wording system!" 
print "What words do you want?" 

while False: 
    word1 = raw_input('enter your word:') 
    word2 = raw_input('enter your word:') 

print word1 
print word2 

if len(word1)>len(word2): 
    word_difference = len(word1) - len(word2) 
    print word1, "is", word_difference, "letters longer than", word2 

elif len(word2)>len(word1): 
    word_difference = len(word2) - len(word1) 
    print word2, "is", word_difference, "letters longer than", word1 

elif len(word1) == len(word2): 
    print word1, "has same number of letters as", word2  

repeat = raw_input("Would you like to enter two more words?(y/n)")  

if repeat == "y": 
    y == False 

,所以我想,如果這個問題問你​​創建從word1 = raw input重複到repeat = raw_input(asking fort two more words)一個代碼,如果no == Good bye!我想知道如何在Python中重複一個過程?

+1

你已經告訴你如何編寫一個while循環...爲什麼不使用另一個? – James 2014-09-10 13:00:28

+3

'while False'永遠不會被執行,因爲它是,呃,不是True。 – cdarke 2014-09-10 13:00:32

+0

它看起來像所有的代碼應該在第一個循環中,只要'repeat'等於「y」(在循環之前已經適當地初始化了'repeat'),它應該執行。 – chepner 2014-09-10 13:03:46

回答

0

只要把所有的代碼在你的循環,其迭代只要repeat(初始化爲「y」等於「y」):

print "You've entered a wording system!" 
print "What words do you want?" 

repeat = "y" 
while repeat == "y": 
    word1 = raw_input('enter your word:') 
    word2 = raw_input('enter your word:') 

    print word1 
    print word2 

    if len(word1)>len(word2): 
     word_difference = len(word1) - len(word2) 
     print word1, "is", word_difference, "letters longer than", word2 

    elif len(word2)>len(word1): 
     word_difference = len(word2) - len(word1) 
     print word2, "is", word_difference, "letters longer than", word1 

    elif len(word1) == len(word2): 
     print word1, "has same number of letters as", word2  

    repeat = raw_input("Would you like to enter two more words?(y/n)") 
相關問題