Py学习  »  Python

如果条件为假python,如何返回第1行

Asim Khan • 6 年前 • 1564 次点击  

如果条件为假,我如何才能回到第一行。

while True:
    food = int(input("food bill: "))
    if food <= 10:
        print("please write more than 10")
#If i put break statement here it does not go forward
    else:
        carbill = int(input("carbill: "))
    print("Total Montlhy expenditure is : " , grandtotal)
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/39065
 
1564 次点击  
文章 [ 2 ]  |  最新文章 6 年前
Matthieu Brucher
Reply   •   1 楼
Matthieu Brucher    6 年前

使用 continue ,它将返回到循环指令(适用于 for 嗯)

jar
Reply   •   2 楼
jar    6 年前

这就是你想要的-

while True:
    food = int(input("food bill: "))
    if food <= 10:
       print("please write more than 10")
       continue
    carbill = int(input("carbill: "))
    print("Total Montlhy expenditure is : " , food+carbill)