Created
October 29, 2019 16:54
-
-
Save eioo/0ca392909cab92017c1f59a99898653c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tulostaLuvunKertoma(n: int) -> None: | |
print(f'{n}! = {laskeKertoma(n)}') | |
def lueKokonaisluku() -> int: | |
return int(input('Anna kokonaisluku: ')) | |
def laskeKertoma(n: int) -> int: | |
factorial = 1 | |
for i in range(1, n + 1): | |
factorial *= i | |
return factorial | |
while True: | |
try: | |
luku = lueKokonaisluku() | |
except ValueError: | |
print('Virheellinen syöte.') | |
continue | |
if luku < 0: | |
print('Ohjelma lopetetaan.') | |
break | |
tulostaLuvunKertoma(luku) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment