> Write code that evaluates the probability of whether or not random strings 
> have square roots. Do not comment on the code.
[PYTHON]
import random

def has_square_root(n):
    for i in range(1, n):
        if i * i == n:
            return True
    return False

def test_has_square_root():
    for i in range(1000):
        n = random.randint(1, 1000000)
        if has_square_root(n):
            assert n**0.5 == int(n**0.5)
        else:
            assert n**0.5 != int(n**0.5)

test_has_square_root()
[/PYTHON]
[TESTS]
# Test case 1:
assert has_square_root(1) == True
# Test case 2:
assert has_square_root(4) == True
# Test case 3:
assert has_square_root(9) == True
# Test case 4:
assert has_square_root(16) == True
# Test case 5:
assert has_square_root(25) == True
[/TESTS]
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
    • Re: [ot... Undescribed Horrific Abuse, One Victim & Survivor of Many
      • Re:... Undescribed Horrific Abuse, One Victim & Survivor of Many
        • ... Undescribed Horrific Abuse, One Victim & Survivor of Many
        • ... Undescribed Horrific Abuse, One Victim & Survivor of Many
        • ... Undescribed Horrific Abuse, One Victim & Survivor of Many
        • ... mailbombbin
        • ... mailbombbin
        • ... mailbombbin
        • ... mailbombbin
        • ... mailbombbin
        • ... mailbombbin
        • ... mailbombbin
        • ... mailbombbin
        • ... mailbombbin
        • ... mailbombbin
        • ... mailbombbin
        • ... mailbombbin
        • ... mailbombbin
        • ... mailbombbin
        • ... mailbombbin

Reply via email to