Chapter 4

 

 

Section 4.1

 

Section 4.2

 

51180

total = 0
k = 50
while k>0:
    total += k * k
    k -= 1

51181

total = 0
k = 0
while k <= n:
    total += k * k * k
    k += 1

51187

i = lo
while i <= hi:
    result += i
    i += 1

51251

q = 0
i = 1
while (i * i < h) :
    q += i * i
    i += 1

51252
q = 0
i = 1
while i * i < h :
    q += 1
    i += 1
51253
i = 1
q = 0
while i * i < k :
    i += 1
while i * i <= m :
    q += 1
    i += 1

Section 4.3

 

51176

total = 0
for k in range(51):
    total += k*k

51177

total = 0
for k in range(n+1):
    total += k*k*k

51259

total = 0
for i in range(1, n+1) :
    total += i
avg = float(total) / n

51250

q = 0
for i in range(1, h+1) :
    q += i * i

51286

sum = 0
for i in range(1, n+1, distance) :
    sum += i

51268

for i in range(2, len(numbers)) :
    if numbers[i] < numbers[i-1] :
        is_ascending = False
        break
else :
    is_ascending = True

51269

for i in range(2, n) :
    if n % i == 0 :
        is_prime = False
        break
else :
    is_prime = True

Section 4.4

 

51094

bridge_players += 4

51095 profits *= 10
51189 total += amount
Section 4.5  

51132

fastestRace = input()
races = input()
while races != "no more races":
    fastestRace = min(fastestRace, races)
    races = input()
print(fastestRace)

51133

grades = input()
counter = 0
sum = 0
while grades != "stop":
    sum += int(grades)
    counter += 1
    grades = input()
print(sum/counter)

51134

buying = input()
while buying != "0":
    if buying == "muffin":
        if muffins > 0:
            muffins -= 1
        else:
            print("Out of stock")
    elif buying == "cupcake":
        if cupcakes > 0:
            cupcakes -= 1
        else:
            print("Out of stock")
    buying = input()
print("muffins:", muffins, "cupcakes:", cupcakes)

51097

b = False
count = 0
while b==False:
    duckGoose = input()
    if duckGoose == "goose":
        print(count)
        b = True
    else:
        count += 1

51178

def fibonacci(n):
    nex = 1
    prev = 0
    for i in range(1, n+1):
        temp = nex
        nex = nex + prev
        prev = temp
    return prev

Section 4.6

 

51135

number = input()
while number != id:
    print("This is not your ID number.")
    number = input()
print("This is your ID number:", number)