Spectrum is now read-only. Learn more about the decision in our official announcement.


Elements of AI is a two part online course about AI and this community is for the participants of the course to discuss. Please join our new community at


Chapter1 ex.4 Advanced

November 10, 2020 at 9:15am

Chapter1 ex.4 Advanced

November 10, 2020 at 9:15am
I separated the area (0-1) into three. And run my program, however, I got following error massages; “Assertion Error: 0 not greater than or equal to 7850” What does it mean?

November 16, 2020 at 6:10pm
This must be some error encountered during the unit tests. If you're still having trouble, you can send me a pm with your code and I can try to help! :)

November 17, 2020 at 6:13am

November 23, 2020 at 8:40pm
I have this same problem. Is there any solution to that you can tell

November 26, 2020 at 3:18pm
Could you try generating a number (the probability with f.x. random.random() ) and then use just an if-then set of cases to decide what to print in each case. At least in hiragi's solution, something might not have gone through the unit tests, but this method should pass the tests. Try it out, and let me know if there's still trouble! :)

December 14, 2020 at 10:50am
Same Problem with either split into three parts (0.8, 0.1, 0.1) or take the dog with 80 Percent and then split 50/50. is it my or your mistake? thx
prob_dog = 0.8 favourite = ['dog', 'cat', 'bat'] if random.random() < prob_dog: print("I love " + favourite[0]) else: r = random.randint(1,2) print("I love " + favourite[r])

December 18, 2020 at 12:53pm
Hello (stweidenauer) ! That was a tricky one. The problem is that your favourite array should be: ['dogs', 'cats', 'bats']. One of those sneaky bugs that are tough to detect! :P
Hi Jonna! Thank you very much. That was frustrating. Now it works...

January 8, 2021 at 5:04am
Similarly, this generates the same assertion error in the test:
def main():
r = random.random()
if r < .80:
favourite = "dogs"
elif r < .90:
favourite = "cats"
favourite = "bats"
print(" I love " + favourite)
This one doesn't.
def main():
r = random.random()
if r < .80:
print("I love dogs")
elif r < .90:
print("I love cats")
print("I love bats")
I am not sure I understand why.

June 21, 2021 at 6:49am
(jazakour) Thanks for reporting this! Some updates we're making had temporarily broken printing, but it should be fixed in a minute from now. Sorry about the trouble!