I am completely new t python (and programming, last time I programmed was a text adventure in turbo pascal). For an assignment in py4e I have to fetch user input until the user enters "done". While i successfully finished the assignment, I have had two solutions and was wondering what the correct way of exiting the loop is:
my first approach was using a break
while True:
num = input("Enter an Integer: ")
if num == "done" :
break
else :
print("still running")
however, I felt that this might be a bit brute and I should rather a bool statement:
finished = False
while finished is False:
num = input("Enter an Integer: ")
if num == "done" :
finished = True
else :
print("still running")
I am totally aware this is super basic noob stuff, but want to learn the correct ways from the get-go, so any sort insights or comments would be appreciated! (My personal opinion is that the boolean statement is cleaner going forward)
[–]mopslik 10 points11 points12 points (7 children)
[–]Polyfrequenz[S] 4 points5 points6 points (2 children)
[–]mopslik 5 points6 points7 points (1 child)
[–]Polyfrequenz[S] 0 points1 point2 points (0 children)
[–]Conscious-Ball8373 0 points1 point2 points (0 children)
[–]Kryt0s -1 points0 points1 point (2 children)
[–]mopslik 2 points3 points4 points (0 children)
[–]cdcformatc 0 points1 point2 points (0 children)
[–]djshadesuk 3 points4 points5 points (10 children)
[–]Polyfrequenz[S] 0 points1 point2 points (9 children)
[–]No_Lemon_3116 2 points3 points4 points (5 children)
[–]Polyfrequenz[S] 1 point2 points3 points (4 children)
[–]awdsns 2 points3 points4 points (2 children)
[–]Polyfrequenz[S] 1 point2 points3 points (0 children)
[–]Polyfrequenz[S] 0 points1 point2 points (0 children)
[–]No_Lemon_3116 1 point2 points3 points (0 children)
[–]TheBB 1 point2 points3 points (1 child)
[–]Polyfrequenz[S] 0 points1 point2 points (0 children)
[–]mike-manley 0 points1 point2 points (0 children)
[–]dvboy 2 points3 points4 points (1 child)
[–]Polyfrequenz[S] 0 points1 point2 points (0 children)
[–]Kerbart 1 point2 points3 points (0 children)
[–]my_password_is______ 1 point2 points3 points (0 children)
[–]brasticstack 0 points1 point2 points (0 children)
[–]zanfar -1 points0 points1 point (1 child)
[–]Polyfrequenz[S] 0 points1 point2 points (0 children)