2017-06-18 72 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,大声笑不要担心。我们都在那里:) –