Guest User

Untitled

a guest
Jan 27th, 2025
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. z = input("enter percentage(don't include %): ")
  2.  
  3. x = float(z) / 100 #decimal value
  4.  
  5. y = 0.0001 #Minimum difference as close to 0 as possible
  6.  
  7. found = False
  8.  
  9. for a in range(1, 1001):
  10. for b in range(1, 1001): #Nested for, so that innerloop iterates completely for every iteration for the outer loop
  11.  
  12. if abs((a / b) - x) <= y:
  13. print(f" {z}% = {a} / {b}")
  14.  
  15. found = True
  16. break
  17.  
  18. if found:
  19. break
Add Comment
Please, Sign In to add comment