Update Lesson 2 Task 3 to be even more simple

This commit is contained in:
Stanislav Mykhailenko 2023-01-24 02:41:17 +02:00
parent 9fd54d6fbc
commit 3825606a00
GPG key ID: 1E95E66A9C9D6A36

View file

@ -2,20 +2,10 @@
# 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)
try: number = int(input("Enter a natural number: "))
except ValueError: numberError()
if number < 1: numberError()
try:
number = int(input("Enter a natural number: "))
if number < 1:
raise ValueError("A natural number is required.")
for i in range(number, 0, -1):
currentNumber = i
@ -23,3 +13,6 @@ for i in range(number, 0, -1):
print(j, end='')
if j > 1: print(' ', end='')
print('')
except ValueError:
print("Invalid number entered.")