(Pyhon 2.7) Hitung Faktorial


Yak, lagi-lagi Python :v Tapi asik sih, ga tau kenapa. Sekarang saya mau share kode untuk perhitungan faktorial. Sebenernya tau dari dosen sih, coba ditulis ulang lagi disini. Mudah-mudahan berguna. Enjoy~

PERHITUNGAN FAKTORIAL

import os
def goto(linenum) :
global line
line = linenum
def faktorial(x) :
if x <= 1 :
return 1
else :
return (x * faktorial(x - 1))
line = 0
while True :
if line == 0 :
os.system('cls')
print '------------------------------'
print 'Hitung Faktorial'
print '------------------------------'
print ''
angka = int(raw_input('Masukkan Angka : '))
print 'Faktorial dari', angka, 'adalah :', faktorial(angka)
print ''
goto(1)
if line == 1 :
ulang = raw_input('Ulang perhitungan? (y/n) : ')
if ulang == 'y' or ulang == 'Y' :
goto(0)
else :
exit(0)
view raw Faktorial.py hosted with ❤ by GitHub


OUTPUT : 

 

SHARE ON:



Legaiabay is a random people who loves playing video games so much and (maybe) an hardcore console gamer. Just writing what I like in good mood, except college work lol. Enjoy, nothing here will interest you :D

    Blogger Comment

0 komentar:

Post a Comment