Last active
December 18, 2021 18:47
-
-
Save MarkCLewis/64438e89bffa3fe22a8ba0539671772e to your computer and use it in GitHub Desktop.
Dice Error Comparison (dynamic vs. static)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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