''' DS2000 Spring 2020 Source code from class -- while loops (**** You're not responsible for the code in main, we were just practicing the loops part! *****) ''' def while_loop_one(): num = 0 while num < 3: print("BEETLEJUICE!") num = num + 1 def while_loop_two(): i = 0 while i < 3: print("i =", i) i = i + 1 def while_loop_three(): i = 10 while i > 0: print("i =", i) i = i - 2 def while_loop_four(): i = 0 while i > 1: print("i =", i) i = i + 1 def while_loop_five(): loop_ok = True x = 0 while loop_ok: print("x =", x) x += 1 if x % 2 == 0: loop_ok = False def while_loop_six(): loop_ok = True x = 0 while loop_ok: print("x =", x) x += 1 if x < 0: loop_ok = False def main(): print("Let's try some loops!!!!\n\n") loop_funcs = [while_loop_one, while_loop_two, while_loop_three, while_loop_four, while_loop_five, while_loop_six] loop_runs = [3, 3, 5, 0, 2, -1] count = 0 while count < len(loop_funcs): guess = int(input("How many times will loop " + str(count + 1) + " run?\n")) print("OK let's see!\n\n") loop_funcs[count]() print("The loop ran", loop_runs[count], "times.") if guess == loop_runs[count]: print("You were right nice job!!!\n\n") else: print("Maybe a little off, just try again!\n\n") count += 1 main()