P106、107 Parrot.py個人理解

prompt = '\nTell me something , and I will  repeat it back to you:'
prompt += "\nEnter 'quit' to end the program.:"
#這個位置亦可以寫prompt = '\nTell me something , and I will  repeat it back to you:\nEnter 'quit' to end the program.'
#這樣寫太長了
#程序運行到這message沒有空值 到while循環 判斷message不等於quit 控制條輸入 輸出message
message = ''
while message != 'quit':
    message = input(prompt)
    print(message)

#active爲True標誌 運行while循環 message爲prompt 到if循環 若message爲quit 更改active爲False 否則輸出message
active = True
while active:
    message = input(prompt)   #輸入quit是會輸出兩邊原因就是在這個位置要 輸出一遍然後在下邊 纔會更改active爲false

    if message == 'quit':
        print ('這個是if')
        active = False
    else:
        print(message)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章