Anonymous user
Trabb Pardo–Knuth algorithm: Difference between revisions
→Procedural: read single number per line; update to more modern Python (string interpolation, walrus operator)
(Trabb Pardo–Knuth algorithm in various BASIC dialents) |
(→Procedural: read single number per line; update to more modern Python (string interpolation, walrus operator)) |
||
Line 3,020:
===Procedural===
{{Works with|Python|3.10}}
<lang python>
def
return
def ask_numbers(n=11):
print(f'Enter {n} numbers:')
return (float(input('>')) for _ in range(n))
if __name__ == '__main__':
if (result := f(x)) > 400:▼
▲ if result > 400:
▲ print(' %s:%s' % (x, "TOO LARGE!"), end='')
else:
print(f'
{{out}}
<pre>Enter 11 numbers:
>1
>532
>465
>0
>-8456
>1
>2
>3
>4
>5
>98465465
f(98465465.0): overflow
f(5.0): overflow
f(4.0) = 322.0
f(3.0) = 136.73205080756887
f(2.0) = 41.41421356237309
f(1.0) = 6.0
f(-8456.0) = -3023186413988.0435
f(0.0) = 0.0
f(465.0): overflow
f(532.0): overflow
f(1.0) = 6.0</pre>
=={{header|R}}==
|