tests
This commit is contained in:
parent
f92f5ef7f6
commit
307c51539c
10 changed files with 252 additions and 1 deletions
29
test/ruby/32.in
Normal file
29
test/ruby/32.in
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue