This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
NG_2022_Stanislav_Mykhailenko/Lesson_2/task3.py

26 lines
565 B
Python
Raw Normal View History

2022-10-27 16:05:50 +00:00
# Lesson 2 Task 3: display all numbers from n to 1, then remove the first number and repeat while n > 0
# Author: Stanislav Mykhailenko
# License: Unlicense
# Return codes:
# 0 - OK
# 1 - Invalid number entered
import math, sys
def numberError():
print("Invalid number entered.")
sys.exit(1)
2022-10-27 16:05:50 +00:00
try: number = int(input("Enter a natural number: "))
except ValueError: numberError()
2022-10-27 16:05:50 +00:00
if number < 1: numberError()
2022-10-27 16:05:50 +00:00
for i in range(number, 0, -1):
currentNumber = i
for j in range(currentNumber, 0, -1):
print(j, end='')
if j > 1: print(' ', end='')
print('')