BuK/IIm20/Vorlesung 12 Seidl

Aus ProgrammingWiki

Wiki-Quelltext dieser Seite.

<language>Python</language>
=== S. 7 ===
<code id="60cdfa9473510">
def in_naturals():
    index = 1
    while True:
        yield index
        index += 1

# n=exponent; a=basis
def pot_loop2(n, a, loops):
    result = 1
    for i in in_naturals():
        if i == loops:
            break
        
        result = result * a
    return result
</code>
<run id="60cdfa9473610">
print(pot_loop2(10, 2, 11))
</run>

=== S. 12 ===
<code id="60cdfa947356f">
def nat():
    index = 0
    while True:
        yield index
        index += 1

def f(x, y):
    for z in range(0, y + 1):
        if ((z + 1) ** 2) > x:
            return z
</code>
<run id="60cdfa9473665">
print(f(19, 19))
</run>

<code id="60cdfa94735be">
def muehf(n):
    m = 0
    while ((m ** 2) - n) != 0:
        m += 1
    n = m
    print(n)
</code>
<run id="60cdfa94736c5">
muehf(4)
</run>