From 593c95e2c46e124e795d95afd6f904c805272e46 Mon Sep 17 00:00:00 2001 From: baphim <269010393+baphim@users.noreply.github.com> Date: Wed, 30 Sep 2026 18:24:13 -0400 Subject: [PATCH] feat: P-1.30 validation loop built --- lab-3_4/P-1.30.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lab-3_4/P-1.30.py b/lab-3_4/P-1.30.py index cc2c434..6ae7fbb 100644 --- a/lab-3_4/P-1.30.py +++ b/lab-3_4/P-1.30.py @@ -1,4 +1,23 @@ """ Write a Python program that can take a positive integer greater than 2 as input and write out the number of times one must repeatedly divide this number by 2 before getting a value less than 2. -""" \ No newline at end of file +""" + +def count_steps(): + # input validation: try that input is an integer + while True: + try: + current_value = int(input('Please enter an integer greater than 2: ')) + # also try that input is above 2, if not print error message + if current_value <= 2: + print('Invalid input: Please enter only integers greater than 2.') + # if input is correct, break the while loop + else: + break + # Handle ValueError and print error message + except ValueError: + print('Invalid input: Please only enter integers.') + + + +count_steps() \ No newline at end of file