dimanche 20 septembre 2020

What does the print mean and its execution?

Can someone help me understand what this code does? The task is that I need to describe what the program does and what the print tells us. I'm really stuck and could use some help!

from random import random

wrong = 0; N = 100000

for i in range(N):
    x = random(); y = random(); z = random()
    res1 = (x + y) * z
    res2 = x*z + y*z
    if res1 != res2:
        wrong += 1
        x0 = x; y0 = y; z0 = z
        notequal1 = res1
        notequal2 = res2

print (100. * wrong/N)
print (x0, y0, z0, notequal1 - notequal2)¨

the code prints out:

30.825
0.7274024508251914 0.7713456905186189 0.06463959172321276 1.3877787807814457e-17



Aucun commentaire:

Enregistrer un commentaire