+ 5

Correction python code

I would like to understand how to definite 3 float numbers and if two of them are similar, the number is printed out (if it isn't, there is no print). from math import random a = float(input()) b = float(input()) c = float(input()) value = random.randint(a, c) value_final = random.randint(a, c) if value_final == value: print(random.randint(a, c)) Where is my syntax error ? According to Python tutor, my code runs but my resolution doesn't suit to the problem. Thanks for your answers

18th Feb 2019, 3:50 AM
Anna
Anna - avatar
2 odpowiedzi
+ 9
Hi Anna There are many problems with your code. Even if it was working, it does something totally different than what you described. The random library is not part of math, so to use it you can: import random The randint function can take only integer parameters, that is causing another error. But I don't get why you used randint in the first place, when you said you want to compare floats from user input. What do you even mean by "similar"? Same as equal, or only to a level of precision? Is 4.0 similar to 3.99999999? I made some changes and the code below does what you explained, but comparing floats with the equality operator will not work on numbers with higher precision. https://code.sololearn.com/c3KDoSwHbvae/?ref=app
18th Feb 2019, 4:33 AM
Tibor Santa
Tibor Santa - avatar
+ 3
Thanks for your explanation and reply !
18th Feb 2019, 7:09 AM
Anna
Anna - avatar