Skip to content

Commit 57eb7f8

Browse files
added example 3
1 parent a3163a6 commit 57eb7f8

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

basics/loops.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,22 @@
7070
goodbye
7171
"""
7272
"""
73-
-------------
73+
---------------
7474
EXAMPLE 3
75-
-------------
76-
"""
75+
---------------
76+
"""
77+
while True: # This wraps the code in a loop
78+
print("Press a 1 to loop and 2 to exit") # Print the question on the screen for the user
79+
press = input("> ") # Input the user or ask the user to type the number of the above screen
80+
if press == "1": # if the user types 1
81+
print("This is a loop") # The program will print this is a loop and loop again
82+
elif press == "2": # If the user types 2 then break or exit the loop
83+
break # This breaks the loop
84+
else: # if the user types anything else other than 1 or 2 it will say Incorrect option selected and loop again until the until the user presses 2 to exit
85+
print("Incorrect option selected")
86+
87+
"""
88+
--------------
89+
EXAMPLE 4
90+
--------------
91+
"""

0 commit comments

Comments
 (0)