(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
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
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) |
OUTPUT :
0 komentar:
Post a Comment