Skip to content

Instantly share code, notes, and snippets.

@eioo
Created October 29, 2019 16:54
Show Gist options
  • Save eioo/0ca392909cab92017c1f59a99898653c to your computer and use it in GitHub Desktop.
Save eioo/0ca392909cab92017c1f59a99898653c to your computer and use it in GitHub Desktop.
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