Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def qsum_calc(value):
- result = 0
- while value:
- result += value % 10
- value //= 10
- return result
- def qsum_single(value):
- while value >= 10:
- value = qsum_calc(value)
- return value
- def get_value():
- while True:
- value = input("Please enter a value between 0 and 999: ")
- try:
- value = int(value)
- except ValueError:
- print(f"'{value}' is not a valid integer.")
- continue
- if 0 <= value <= 999:
- return value
- else:
- print(f"'{value}' is not between 0 and 999")
- def main():
- while True:
- value = get_value()
- result = qsum_single(value)
- print(f"Result: {result}")
- if __name__ == "__main__":
- try:
- main()
- except KeyboardInterrupt:
- print()
- print("Goodbye")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement