29 lines
No EOL
573 B
Text
29 lines
No EOL
573 B
Text
def countdown(n):
|
|
while n > 0:
|
|
print(f"Countdown: {n}")
|
|
n -= 1
|
|
print("Blast off!")
|
|
|
|
def sum_until_negative():
|
|
total = 0
|
|
count = 0
|
|
inputs = [5, 3, 8, -1, 4, 2]
|
|
|
|
for value in inputs:
|
|
if value < 0:
|
|
break
|
|
total += value
|
|
count += 1
|
|
|
|
if count > 0:
|
|
average = total / count
|
|
return total, average
|
|
else:
|
|
return 0, 0
|
|
|
|
print("Countdown from 5:")
|
|
countdown(5)
|
|
|
|
print("\nSum until negative:")
|
|
total, avg = sum_until_negative()
|
|
print(f"Total: {total}, Average: {avg:.2f}") |