“Rekursi di Python” Kode Jawaban

Bagaimana Rekursi Bekerja Dalam Python

def factorial(x):
    """This is a recursive function
    to find the factorial of an integer"""

    if x == 1:
        return 1
    else:
        return (x * factorial(x-1))


num = 1
print("The factorial of", num, "is", factorial(num))
Panicky Penguin

Rekursi di Python

def rec(num):
    if num <= 1:
        return 1
    else:
        return num + rec(num - 1)

print(rec(50))    
Defeated Dunlin

Contoh Rekursi Python

# Recursive function factorial_recursion()

def factorial_recursion(n):  
   if n == 1:  
       return n  
   else:  
       return n*factorial_recursion(n-1)
Anxious Ape

Apa itu fungsi rekursif Python di Python

 pythonCopydef fact(n):
    """Recursive function to find factorial"""
    if n == 1:
        return 1
    else:
        return (n * fact(n - 1))
a = 6
print("Factorial of", a, "=", fact(a))
Shy Skunk

Python rekursif

import random


def guess(a,b):
    x = random.randint(a,b)
    return x


def check(x,y):
    if y ** 2 == x:
        return True
    return False


x = 100
left, right = 0, x
y = guess(left, right)
while not check(x,y):
    y = guess(left, right)
print(y)
Concerned Caterpillar

Jawaban yang mirip dengan “Rekursi di Python”

Pertanyaan yang mirip dengan “Rekursi di Python”

Lebih banyak jawaban terkait untuk “Rekursi di Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya