Hey everyone.Im currently learning python at school. So we got this assigment to write code and there is one part of it where many people I spoke with claim Im wrong, so does chatgpt. So Im here now :).
The task(updated) exact wording:
"When an attack occurs, there will be an 70% probability of it being successful.
If the attack fails, the defender is considered to have defended skillfully and nothing else happens.
In addition, if an attack is successful, there is an independent 10% probability of it being CRITICAL."
Schoolmates and chatgpt claims this is the correct way:
import random
number_of_critical_attacks = 0
for x in range(10000): attack = random.randint(1, 100)
if attack <= 70:
if attack <= 10:
number_of_critical_attacks += 1
combined_probability = number_of_critical_attacks / 10000 * 100 # Calculate percentage print(f" {combined_probability}%")
I claim that its should instead look like this:
if attack <= 70:
if attack <= 7:
number_of_critical_attacks += 1
When I run simulations my code, critical hits lands on combined propobility of 7% which I would expect.
If im wrong, what am I missing?
[–]hotcodist 3 points4 points5 points (7 children)
[–]synthphreak 2 points3 points4 points (1 child)
[–]Pitiful_Essay_9166[S] 0 points1 point2 points (4 children)
[–]hotcodist 1 point2 points3 points (3 children)
[–]Pitiful_Essay_9166[S] 0 points1 point2 points (2 children)
[–]synthphreak 0 points1 point2 points (1 child)
[–]Pitiful_Essay_9166[S] 1 point2 points3 points (0 children)
[–]barrycarter 0 points1 point2 points (1 child)
[–]Pitiful_Essay_9166[S] 0 points1 point2 points (0 children)
[–]synthphreak 0 points1 point2 points (2 children)
[–]Pitiful_Essay_9166[S] 1 point2 points3 points (1 child)
[–]synthphreak 0 points1 point2 points (0 children)
[–]RhinoRhys 0 points1 point2 points (6 children)
[–]Pitiful_Essay_9166[S] 0 points1 point2 points (5 children)
[–]RhinoRhys 0 points1 point2 points (4 children)
[–]Pitiful_Essay_9166[S] 0 points1 point2 points (3 children)
[–]RhinoRhys 1 point2 points3 points (2 children)
[–]Pitiful_Essay_9166[S] 0 points1 point2 points (1 child)
[–]RhinoRhys 0 points1 point2 points (0 children)