0% found this document useful (0 votes)
17 views1 page

Count and Reverse Three-Digit Integers

The document describes a Python script that continuously prompts the user to enter integers until they input 'false' to stop. It counts how many three-digit integers are entered and reverses each valid integer, storing the results in a list. If the input is not a valid integer, it prompts the user to enter a valid input again.

Uploaded by

vibeshanakumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Count and Reverse Three-Digit Integers

The document describes a Python script that continuously prompts the user to enter integers until they input 'false' to stop. It counts how many three-digit integers are entered and reverses each valid integer, storing the results in a list. If the input is not a valid integer, it prompts the user to enter a valid input again.

Uploaded by

vibeshanakumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

while True:

user_input = input("Enter an integer: ")

# Check if the user wants to stop


if user_input.lower() == "false":
break

# Ensure the input is a valid integer


try:
number = int(user_input)

# Check if it's a three-digit number


if 100 <= abs(number) <= 999:
three_digit_count += 1

# Reverse the integer manually


reversed_number = 0
temp = abs(number) # Work with positive value for reversal
while temp > 0:
reversed_number = reversed_number * 10 + temp % 10
temp //= 10
# Restore the sign of the number
if number < 0:
reversed_number = -reversed_number

reversed_numbers.append(reversed_number)
except ValueError:
print("Invalid input. Please enter a valid integer or 'false' to stop.")

# Output results
print("\nNumber of three-digit integers entered:", three_digit_count)
print("Reversed integers:", reversed_numbers)

You might also like