Update Lesson 2 Task 3 to be even more simple
This commit is contained in:
parent
9fd54d6fbc
commit
3825606a00
1 changed files with 11 additions and 18 deletions
|
@ -2,24 +2,17 @@
|
||||||
# Author: Stanislav Mykhailenko
|
# Author: Stanislav Mykhailenko
|
||||||
# License: Unlicense
|
# License: Unlicense
|
||||||
|
|
||||||
# Return codes:
|
try:
|
||||||
# 0 - OK
|
number = int(input("Enter a natural number: "))
|
||||||
# 1 - Invalid number entered
|
if number < 1:
|
||||||
|
raise ValueError("A natural number is required.")
|
||||||
|
|
||||||
import math, sys
|
for i in range(number, 0, -1):
|
||||||
|
|
||||||
def numberError():
|
|
||||||
print("Invalid number entered.")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try: number = int(input("Enter a natural number: "))
|
|
||||||
except ValueError: numberError()
|
|
||||||
|
|
||||||
if number < 1: numberError()
|
|
||||||
|
|
||||||
for i in range(number, 0, -1):
|
|
||||||
currentNumber = i
|
currentNumber = i
|
||||||
for j in range(currentNumber, 0, -1):
|
for j in range(currentNumber, 0, -1):
|
||||||
print(j, end='')
|
print(j, end='')
|
||||||
if j > 1: print(' ', end='')
|
if j > 1: print(' ', end='')
|
||||||
print('')
|
print('')
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
print("Invalid number entered.")
|
||||||
|
|
Reference in a new issue