2017-06-18 82 views
0

不理解如何讓循環停止和繼續/重複 也,不明白如何讓布爾的第二部分工作while循環和布爾

monthly_investment = float(input("Enter monthly investment:\t")) 
while monthly_investment < 1: 
    print("Entry must be greater than 0") 

yearly_interest_rate = float(input("Enter yearly interest rate:\t")) 
while yearly_interest_rate < 1 and yearly_interest_rate < 16: 
    print("Entry must be greater than 0 and less than or equal to 15") 
+1

https://www.tutorialspoint.com/python/python_while_loop.htm –

+0

我理解的循環只是沒怎麼回去,如果該值是Ø – Nimkora

+0

回去的地方?如果您想根據條件進行操作,請使用if語句 –

回答

0

Nimkora,

你只需要在while循環結束時添加另一個賦值語句,以便用戶輸入一個有效的輸入時,程序可以跳出while循環。

monthly_investment = float(input("Enter monthly investment:\t")) 
while monthly_investment < 1: 
    print("Entry must be greater than 0") 
    monthly_investment = float(input("Enter monthly investment:\t")) 

yearly_interest_rate = float(input("Enter yearly interest rate:\t")) 
while yearly_interest_rate < 1 and yearly_interest_rate < 16: 
    print("Entry must be greater than 0 and less than or equal to 15") 
    yearly_interest_rate = float(input("Enter yearly interest rate:\t")) 
+0

即時消息一個白癡大聲笑謝謝 – Nimkora

+0

@Nimkora,大聲笑不要擔心。我們都在那裏:) –