Skip to content

Instantly share code, notes, and snippets.

@MarkCLewis
Last active December 18, 2021 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkCLewis/64438e89bffa3fe22a8ba0539671772e to your computer and use it in GitHub Desktop.
Save MarkCLewis/64438e89bffa3fe22a8ba0539671772e to your computer and use it in GitHub Desktop.
Dice Error Comparison (dynamic vs. static)
import random
def attack():
d1 = random.randint(1, 6)
d2 = random.randint(1, 6)
n = d1 + d2
if n == 2:
n = 'critical miss!'
elif n < 8:
m = 'weak hit.'
elif n < 12:
m = 'good hit.'
else:
m = 'critical hit!'
return (n, m)
(damage, message) = attack()
print(f'You got a {message}.')
print(f'You did {damage} damage.')
def attack(): (Int, String) =
val d1 = util.Random.between(1, 7)
val d2 = util.Random.between(1, 7)
val n = d1 + d2
if n == 2 then
n = "critical miss!"
else if n < 8 then
val m = "weak hit."
else if n < 12 then
val m = "good hit."
else
val m = "critical hit!"
(n, m)
@main def start =
val (damage, message) = attack()
println(s"You got a $message.")
println(s"You did $damage damage.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment